fix doc example typo
[boost.git] / boost / ptr_container / indirect_fun.hpp
blob7770b53ef2f05097583ac38bf01b69cc7922a34e
1 //
2 // Boost.Pointer Container
3 //
4 // Copyright Thorsten Ottosen 2003-2007. 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/
12 #ifndef BOOST_PTR_CONTAINER_INDIRECT_FUN_HPP
13 #define BOOST_PTR_CONTAINER_INDIRECT_FUN_HPP
15 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #pragma once
17 #endif
19 #include <boost/config.hpp>
21 #ifdef BOOST_NO_SFINAE
22 #else
23 #include <boost/utility/result_of.hpp>
24 #include <boost/pointee.hpp>
25 #endif // BOOST_NO_SFINAE
27 #include <boost/assert.hpp>
28 #include <functional>
31 namespace boost
35 template
37 class Fun
38 #ifdef BOOST_NO_SFINAE
39 , class Result = bool
40 #endif
42 class indirect_fun
44 Fun fun;
45 public:
46 indirect_fun() : fun(Fun())
47 { }
49 indirect_fun( Fun f ) : fun(f)
50 { }
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
60 return fun( *r );
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
72 return fun( *r, *r2 );
76 template< class Fun >
77 inline indirect_fun<Fun> make_indirect_fun( Fun f )
79 return indirect_fun<Fun>( f );
83 template
85 class Fun,
86 class Arg1,
87 class Arg2 = Arg1
88 #ifdef BOOST_NO_SFINAE
89 , class Result = bool
90 #endif
92 class void_ptr_indirect_fun
94 Fun fun;
95 public:
97 void_ptr_indirect_fun() : fun(Fun())
98 { }
100 void_ptr_indirect_fun( Fun f ) : fun(f)
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
109 BOOST_ASSERT( r != 0 );
110 return fun( * static_cast<const Arg1*>( r ) );
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
120 BOOST_ASSERT( l != 0 && r != 0 );
121 return fun( * static_cast<const Arg1*>( l ), * static_cast<const Arg2*>( r ) );
125 template< class Arg, class Fun >
126 inline void_ptr_indirect_fun<Fun,Arg> make_void_ptr_indirect_fun( Fun f )
128 return void_ptr_indirect_fun<Fun,Arg>( f );
131 } // namespace 'boost'
133 #endif