1 | // |
---|
2 | // Boost.Pointer Container |
---|
3 | // |
---|
4 | // Copyright Thorsten Ottosen 2003-2005. Use, modification and |
---|
5 | // distribution is subject to the Boost Software License, Version |
---|
6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
---|
7 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
8 | // |
---|
9 | // For more information, see http://www.boost.org/libs/ptr_container/ |
---|
10 | // |
---|
11 | |
---|
12 | #ifndef BOOST_PTR_CONTAINER_INDIRECT_FUN_HPP |
---|
13 | #define BOOST_PTR_CONTAINER_INDIRECT_FUN_HPP |
---|
14 | |
---|
15 | #if defined(_MSC_VER) && (_MSC_VER >= 1200) |
---|
16 | #pragma once |
---|
17 | #endif |
---|
18 | |
---|
19 | #include <boost/config.hpp> |
---|
20 | |
---|
21 | #ifdef BOOST_NO_SFINAE |
---|
22 | #else |
---|
23 | #include <boost/utility/result_of.hpp> |
---|
24 | #include <boost/pointee.hpp> |
---|
25 | #endif // BOOST_NO_SFINAE |
---|
26 | |
---|
27 | #include <boost/assert.hpp> |
---|
28 | #include <functional> |
---|
29 | |
---|
30 | |
---|
31 | namespace boost |
---|
32 | { |
---|
33 | |
---|
34 | |
---|
35 | template |
---|
36 | < |
---|
37 | class Fun |
---|
38 | #ifdef BOOST_NO_SFINAE |
---|
39 | , class Result = bool |
---|
40 | #endif |
---|
41 | > |
---|
42 | class indirect_fun |
---|
43 | { |
---|
44 | Fun fun; |
---|
45 | public: |
---|
46 | indirect_fun() : fun(Fun()) |
---|
47 | { } |
---|
48 | |
---|
49 | indirect_fun( Fun f ) : fun(f) |
---|
50 | { } |
---|
51 | |
---|
52 | template< class T > |
---|
53 | #ifdef BOOST_NO_SFINAE |
---|
54 | Result |
---|
55 | #else |
---|
56 | BOOST_DEDUCED_TYPENAME result_of< Fun( BOOST_DEDUCED_TYPENAME pointee<T>::type ) >::type |
---|
57 | #endif |
---|
58 | operator()( const T& r ) const |
---|
59 | { |
---|
60 | return fun( *r ); |
---|
61 | } |
---|
62 | |
---|
63 | template< class T, class U > |
---|
64 | #ifdef BOOST_NO_SFINAE |
---|
65 | Result |
---|
66 | #else |
---|
67 | BOOST_DEDUCED_TYPENAME result_of< Fun( BOOST_DEDUCED_TYPENAME pointee<T>::type, |
---|
68 | BOOST_DEDUCED_TYPENAME pointee<U>::type ) >::type |
---|
69 | #endif |
---|
70 | operator()( const T& r, const U& r2 ) const |
---|
71 | { |
---|
72 | return fun( *r, *r2 ); |
---|
73 | } |
---|
74 | }; |
---|
75 | |
---|
76 | template< class Fun > |
---|
77 | inline indirect_fun<Fun> make_indirect_fun( Fun f ) |
---|
78 | { |
---|
79 | return indirect_fun<Fun>( f ); |
---|
80 | } |
---|
81 | |
---|
82 | |
---|
83 | template |
---|
84 | < |
---|
85 | class Fun, |
---|
86 | class Arg1, |
---|
87 | class Arg2 = Arg1 |
---|
88 | #ifdef BOOST_NO_SFINAE |
---|
89 | , class Result = bool |
---|
90 | #endif |
---|
91 | > |
---|
92 | class void_ptr_indirect_fun |
---|
93 | { |
---|
94 | Fun fun; |
---|
95 | public: |
---|
96 | |
---|
97 | void_ptr_indirect_fun() : fun(Fun()) |
---|
98 | { } |
---|
99 | |
---|
100 | void_ptr_indirect_fun( Fun f ) : fun(f) |
---|
101 | { } |
---|
102 | #ifdef BOOST_NO_SFINAE |
---|
103 | Result |
---|
104 | #else |
---|
105 | BOOST_DEDUCED_TYPENAME result_of< Fun( Arg1 ) >::type |
---|
106 | #endif |
---|
107 | operator()( const void* r ) const |
---|
108 | { |
---|
109 | BOOST_ASSERT( r != 0 ); |
---|
110 | return fun( * static_cast<const Arg1*>( r ) ); |
---|
111 | } |
---|
112 | |
---|
113 | #ifdef BOOST_NO_SFINAE |
---|
114 | Result |
---|
115 | #else |
---|
116 | BOOST_DEDUCED_TYPENAME result_of< Fun( Arg1, Arg2 ) >::type |
---|
117 | #endif |
---|
118 | operator()( const void* l, const void* r ) const |
---|
119 | { |
---|
120 | BOOST_ASSERT( l != 0 && r != 0 ); |
---|
121 | return fun( * static_cast<const Arg1*>( l ), * static_cast<const Arg2*>( r ) ); |
---|
122 | } |
---|
123 | }; |
---|
124 | |
---|
125 | template< class Arg, class Fun > |
---|
126 | inline void_ptr_indirect_fun<Fun,Arg> make_void_ptr_indirect_fun( Fun f ) |
---|
127 | { |
---|
128 | return void_ptr_indirect_fun<Fun,Arg>( f ); |
---|
129 | } |
---|
130 | |
---|
131 | } // namespace 'boost' |
---|
132 | |
---|
133 | #endif |
---|