Move libcds 1.6.0 from SVN
[libcds.git] / cds / details / binary_functor_wrapper.h
1 //$$CDS-header$$
2
3 #ifndef __CDS_DETAILS_BINARY_FUNCTOR_WRAPPER_H
4 #define __CDS_DETAILS_BINARY_FUNCTOR_WRAPPER_H
5
6 #include <cds/details/defs.h>
7
8 //@cond
9 namespace cds { namespace details {
10
11     template <typename ReturnType, typename Functor, typename ArgType, typename Accessor>
12     struct binary_functor_wrapper {
13         typedef ReturnType  return_type;
14         typedef Functor     functor_type;
15         typedef ArgType     argument_type;
16         typedef Accessor    accessor;
17
18         return_type operator()( argument_type const& a1, argument_type const& a2 ) const
19         {
20             return functor_type()( accessor()( a1 ), accessor()( a2 ));
21         }
22
23         template <typename Q>
24         return_type operator()( argument_type const& a, Q const& q ) const
25         {
26             return functor_type()( accessor()(a), q );
27         }
28
29         template <typename Q>
30         return_type operator()( Q const& q, argument_type const& a ) const
31         {
32             return functor_type()( q, accessor()(a));
33         }
34
35         template <typename Q1, typename Q2>
36         return_type operator()( Q1 const& q1, Q2 const& q2 ) const
37         {
38             return functor_type()( q1, q2 );
39         }
40     };
41
42 #ifdef CDS_CXX11_TEMPLATE_ALIAS_SUPPORT
43     template <typename ArgType, typename Predicate, typename Accessor>
44     using predicate_wrapper = binary_functor_wrapper< bool, Predicate, ArgType, Accessor>;
45
46     template <typename ArgType, typename Compare, typename Accessor>
47     using compare_wrapper = binary_functor_wrapper< int, Compare, ArgType, Accessor>;
48 #else
49     template <typename ArgType, typename Predicate, typename Accessor>
50     struct predicate_wrapper: public binary_functor_wrapper< bool, Predicate, ArgType, Accessor>
51     {};
52
53     template <typename ArgType, typename Compare, typename Accessor>
54     struct compare_wrapper: public binary_functor_wrapper< int, Compare, ArgType, Accessor >
55     {};
56 #endif
57
58 }} // namespace cds::details
59
60 //@endcond
61
62 #endif // #ifndef __CDS_DETAILS_BINARY_FUNCTOR_WRAPPER_H