From 30343c8d3eee26d0f4ca8dd84c68d1350304021a Mon Sep 17 00:00:00 2001 From: Mike Krinkin Date: Sat, 28 Mar 2015 09:58:27 +0300 Subject: [PATCH] Derive equal_to from compare/less functors. For unordered lists it is possible to derive equal_to from compare or less functors. This patch fixes make_equal_to so that it returns equal_to if it is specified, else if compare is specified it derives equal_to from compare functor, otherwise it derives equal_to from less functor. --- cds/opt/compare.h | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/cds/opt/compare.h b/cds/opt/compare.h index 3bcfc961..1243f5be 100644 --- a/cds/opt/compare.h +++ b/cds/opt/compare.h @@ -244,16 +244,52 @@ namespace cds { namespace opt { //@cond namespace details { + template + struct make_equal_to_from_compare + { + typedef Compare compare_functor; + + template + bool operator()( T const& t, Q const& q ) const + { + compare_functor cmp; + return cmp(t, q) == 0; + } + }; + + template + struct make_equal_to_from_less + { + typedef Less less_functor; + + template + bool operator()( T const& t, Q const& q ) const + { + less_functor less; + return !less(t, q) && !less(q, t); + } + }; + template struct make_equal_to { typedef typename Traits::equal_to equal_to; + typedef typename Traits::compare compare; + typedef typename Traits::less less; typedef typename std::conditional< std::is_same< equal_to, opt::none >::value, - typename std::conditional< Forced, std::equal_to, opt::none >::type, - equal_to - >::type type; + typename std::conditional< + std::is_same< compare, opt::none >::value, + typename std::conditional< + std::is_same< less, opt::none >::value, + typename std::conditional< + Forced, + std::equal_to, + opt::none >::type, + make_equal_to_from_less< less > >::type, + make_equal_to_from_compare< compare > >::type, + equal_to >::type type; }; } //@endcond -- 2.34.1