]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Boost.Assign library |
2 | // | |
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) | |
7 | // | |
8 | // For more information, see http://www.boost.org/libs/assign/ | |
9 | // | |
10 | ||
11 | #ifndef BOOST_ASSIGN_PTR_LIST_INSERTER_HPP | |
12 | #define BOOST_ASSIGN_PTR_LIST_INSERTER_HPP | |
13 | ||
14 | #if defined(_MSC_VER) | |
15 | # pragma once | |
16 | #endif | |
17 | ||
18 | #include <boost/assign/list_inserter.hpp> | |
19 | #include <boost/type_traits/remove_reference.hpp> | |
20 | #include <boost/type_traits/remove_pointer.hpp> | |
92f5a8d4 TL |
21 | #include <boost/move/utility.hpp> |
22 | ||
23 | #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) | |
24 | ||
25 | #include <boost/preprocessor/repetition/enum_binary_params.hpp> | |
26 | #include <boost/preprocessor/repetition/enum_params.hpp> | |
27 | #include <boost/preprocessor/iteration/local.hpp> | |
28 | ||
29 | #endif | |
7c673cae FG |
30 | |
31 | namespace boost | |
32 | { | |
33 | ||
34 | namespace assign | |
35 | { | |
36 | template< class Function, class Obj > | |
37 | class ptr_list_inserter | |
38 | { | |
39 | typedef BOOST_DEDUCED_TYPENAME | |
40 | remove_pointer< BOOST_DEDUCED_TYPENAME | |
41 | remove_reference<Obj>::type >::type | |
42 | obj_type; | |
43 | public: | |
44 | ||
45 | ptr_list_inserter( Function fun ) : insert_( fun ) | |
46 | {} | |
47 | ||
48 | template< class Function2, class Obj2 > | |
49 | ptr_list_inserter( const ptr_list_inserter<Function2,Obj2>& r ) | |
50 | : insert_( r.fun_private() ) | |
51 | {} | |
52 | ||
53 | ptr_list_inserter( const ptr_list_inserter& r ) : insert_( r.insert_ ) | |
54 | {} | |
55 | ||
92f5a8d4 TL |
56 | |
57 | #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) | |
7c673cae FG |
58 | ptr_list_inserter& operator()() |
59 | { | |
60 | insert_( new obj_type() ); | |
61 | return *this; | |
62 | } | |
63 | ||
64 | template< class T > | |
65 | ptr_list_inserter& operator()( const T& t ) | |
66 | { | |
67 | insert_( new obj_type(t) ); | |
68 | return *this; | |
69 | } | |
70 | ||
71 | #ifndef BOOST_ASSIGN_MAX_PARAMS // use user's value | |
72 | #define BOOST_ASSIGN_MAX_PARAMS 5 | |
73 | #endif | |
74 | #define BOOST_ASSIGN_MAX_PARAMETERS (BOOST_ASSIGN_MAX_PARAMS - 1) | |
75 | #define BOOST_ASSIGN_PARAMS1(n) BOOST_PP_ENUM_PARAMS(n, class T) | |
76 | #define BOOST_ASSIGN_PARAMS2(n) BOOST_PP_ENUM_BINARY_PARAMS(n, T, const& t) | |
77 | #define BOOST_ASSIGN_PARAMS3(n) BOOST_PP_ENUM_PARAMS(n, t) | |
78 | ||
79 | #define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS) | |
80 | #define BOOST_PP_LOCAL_MACRO(n) \ | |
81 | template< class T, BOOST_ASSIGN_PARAMS1(n) > \ | |
82 | ptr_list_inserter& operator()( const T& t, BOOST_ASSIGN_PARAMS2(n) ) \ | |
83 | { \ | |
84 | insert_( new obj_type(t, BOOST_ASSIGN_PARAMS3(n) )); \ | |
85 | return *this; \ | |
86 | } \ | |
87 | /**/ | |
88 | ||
89 | #include BOOST_PP_LOCAL_ITERATE() | |
90 | ||
92f5a8d4 TL |
91 | #else |
92 | ||
93 | template< class... Ts > | |
94 | ptr_list_inserter& operator()(Ts&&... ts) | |
95 | { | |
96 | insert_(new obj_type(boost::forward<Ts>(ts)...)); | |
97 | return *this; | |
98 | } | |
99 | ||
100 | #endif | |
101 | ||
7c673cae FG |
102 | private: |
103 | ||
104 | ptr_list_inserter& operator=( const ptr_list_inserter& ); | |
105 | Function insert_; | |
106 | }; | |
107 | ||
108 | template< class Obj, class Function > | |
109 | inline ptr_list_inserter< Function, Obj > | |
110 | make_ptr_list_inserter( Function fun ) | |
111 | { | |
112 | return ptr_list_inserter< Function, Obj >( fun ); | |
113 | } | |
114 | ||
115 | template< class C > | |
116 | inline ptr_list_inserter< assign_detail::call_push_back<C>, | |
117 | BOOST_DEDUCED_TYPENAME C::reference > | |
118 | ptr_push_back( C& c ) | |
119 | { | |
120 | return make_ptr_list_inserter<BOOST_DEDUCED_TYPENAME C::reference> | |
121 | ( assign_detail::call_push_back<C>( c ) ); | |
122 | } | |
123 | ||
124 | #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING | |
125 | ||
126 | template< class T, class C > | |
127 | inline ptr_list_inserter< assign_detail::call_push_back<C>, T > | |
128 | ptr_push_back( C& c ) | |
129 | { | |
130 | return make_ptr_list_inserter<T>( | |
131 | assign_detail::call_push_back<C>( c ) ); | |
132 | } | |
133 | ||
134 | #endif | |
135 | ||
136 | template< class C > | |
137 | inline ptr_list_inserter< assign_detail::call_push_front<C>, | |
138 | BOOST_DEDUCED_TYPENAME C::reference > | |
139 | ptr_push_front( C& c ) | |
140 | { | |
141 | return make_ptr_list_inserter<BOOST_DEDUCED_TYPENAME C::reference> | |
142 | ( assign_detail::call_push_front<C>( c ) ); | |
143 | } | |
144 | ||
145 | #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING | |
146 | ||
147 | template< class T, class C > | |
148 | inline ptr_list_inserter< assign_detail::call_push_front<C>, T > | |
149 | ptr_push_front( C& c ) | |
150 | { | |
151 | return make_ptr_list_inserter<T>( | |
152 | assign_detail::call_push_front<C>( c ) ); | |
153 | } | |
154 | ||
155 | #endif | |
156 | ||
157 | template< class C > | |
158 | inline ptr_list_inserter< assign_detail::call_insert<C>, | |
159 | BOOST_DEDUCED_TYPENAME C::reference> | |
160 | ptr_insert( C& c ) | |
161 | { | |
162 | return make_ptr_list_inserter<BOOST_DEDUCED_TYPENAME C::reference> | |
163 | ( assign_detail::call_insert<C>( c ) ); | |
164 | } | |
165 | ||
166 | #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING | |
167 | ||
168 | template< class T, class C > | |
169 | inline ptr_list_inserter< assign_detail::call_insert<C>, T > | |
170 | ptr_insert( C& c ) | |
171 | { | |
172 | return make_ptr_list_inserter<T>( assign_detail::call_insert<C>( c ) ); | |
173 | } | |
174 | ||
175 | #endif | |
176 | ||
177 | ||
178 | } // namespace 'assign' | |
179 | } // namespace 'boost' | |
180 | ||
92f5a8d4 TL |
181 | #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) |
182 | ||
7c673cae FG |
183 | #undef BOOST_ASSIGN_PARAMS1 |
184 | #undef BOOST_ASSIGN_PARAMS2 | |
185 | #undef BOOST_ASSIGN_PARAMS3 | |
186 | #undef BOOST_ASSIGN_MAX_PARAMETERS | |
187 | ||
188 | #endif | |
92f5a8d4 TL |
189 | |
190 | #endif |