1 // Boost.Assign library
3 // Copyright Thorsten Ottosen 2003-2005. Use, modification and
4 // distribution is subject to the Boost Software License, Version
5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 // For more information, see http://www.boost.org/libs/assign/
11 #ifndef BOOST_ASSIGN_PTR_LIST_INSERTER_HPP
12 #define BOOST_ASSIGN_PTR_LIST_INSERTER_HPP
18 #include <boost/assign/list_inserter.hpp>
19 #include <boost/type_traits/remove_reference.hpp>
20 #include <boost/type_traits/remove_pointer.hpp>
27 template< class Function, class Obj >
28 class ptr_list_inserter
30 typedef BOOST_DEDUCED_TYPENAME
31 remove_pointer< BOOST_DEDUCED_TYPENAME
32 remove_reference<Obj>::type >::type
36 ptr_list_inserter( Function fun ) : insert_( fun )
39 template< class Function2, class Obj2 >
40 ptr_list_inserter( const ptr_list_inserter<Function2,Obj2>& r )
41 : insert_( r.fun_private() )
44 ptr_list_inserter( const ptr_list_inserter& r ) : insert_( r.insert_ )
47 ptr_list_inserter& operator()()
49 insert_( new obj_type() );
54 ptr_list_inserter& operator()( const T& t )
56 insert_( new obj_type(t) );
60 #ifndef BOOST_ASSIGN_MAX_PARAMS // use user's value
61 #define BOOST_ASSIGN_MAX_PARAMS 5
63 #define BOOST_ASSIGN_MAX_PARAMETERS (BOOST_ASSIGN_MAX_PARAMS - 1)
64 #define BOOST_ASSIGN_PARAMS1(n) BOOST_PP_ENUM_PARAMS(n, class T)
65 #define BOOST_ASSIGN_PARAMS2(n) BOOST_PP_ENUM_BINARY_PARAMS(n, T, const& t)
66 #define BOOST_ASSIGN_PARAMS3(n) BOOST_PP_ENUM_PARAMS(n, t)
68 #define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS)
69 #define BOOST_PP_LOCAL_MACRO(n) \
70 template< class T, BOOST_ASSIGN_PARAMS1(n) > \
71 ptr_list_inserter& operator()( const T& t, BOOST_ASSIGN_PARAMS2(n) ) \
73 insert_( new obj_type(t, BOOST_ASSIGN_PARAMS3(n) )); \
78 #include BOOST_PP_LOCAL_ITERATE()
82 ptr_list_inserter& operator=( const ptr_list_inserter& );
86 template< class Obj, class Function >
87 inline ptr_list_inserter< Function, Obj >
88 make_ptr_list_inserter( Function fun )
90 return ptr_list_inserter< Function, Obj >( fun );
94 inline ptr_list_inserter< assign_detail::call_push_back<C>,
95 BOOST_DEDUCED_TYPENAME C::reference >
98 return make_ptr_list_inserter<BOOST_DEDUCED_TYPENAME C::reference>
99 ( assign_detail::call_push_back<C>( c ) );
102 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
104 template< class T, class C >
105 inline ptr_list_inserter< assign_detail::call_push_back<C>, T >
106 ptr_push_back( C& c )
108 return make_ptr_list_inserter<T>(
109 assign_detail::call_push_back<C>( c ) );
115 inline ptr_list_inserter< assign_detail::call_push_front<C>,
116 BOOST_DEDUCED_TYPENAME C::reference >
117 ptr_push_front( C& c )
119 return make_ptr_list_inserter<BOOST_DEDUCED_TYPENAME C::reference>
120 ( assign_detail::call_push_front<C>( c ) );
123 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
125 template< class T, class C >
126 inline ptr_list_inserter< assign_detail::call_push_front<C>, T >
127 ptr_push_front( C& c )
129 return make_ptr_list_inserter<T>(
130 assign_detail::call_push_front<C>( c ) );
136 inline ptr_list_inserter< assign_detail::call_insert<C>,
137 BOOST_DEDUCED_TYPENAME C::reference>
140 return make_ptr_list_inserter<BOOST_DEDUCED_TYPENAME C::reference>
141 ( assign_detail::call_insert<C>( c ) );
144 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
146 template< class T, class C >
147 inline ptr_list_inserter< assign_detail::call_insert<C>, T >
150 return make_ptr_list_inserter<T>( assign_detail::call_insert<C>( c ) );
156 } // namespace 'assign'
157 } // namespace 'boost'
159 #undef BOOST_ASSIGN_PARAMS1
160 #undef BOOST_ASSIGN_PARAMS2
161 #undef BOOST_ASSIGN_PARAMS3
162 #undef BOOST_ASSIGN_MAX_PARAMETERS