File indexing completed on 2025-01-18 09:29:13
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASSIGN_LIST_INSERTER_HPP
0012 #define BOOST_ASSIGN_LIST_INSERTER_HPP
0013
0014 #if defined(_MSC_VER)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/detail/workaround.hpp>
0019
0020 #include <boost/type_traits/conditional.hpp>
0021 #include <boost/type_traits/is_same.hpp>
0022 #include <boost/range/begin.hpp>
0023 #include <boost/range/end.hpp>
0024 #include <boost/config.hpp>
0025 #include <boost/move/utility.hpp>
0026 #include <cstddef>
0027
0028 #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0029
0030 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
0031 #include <boost/preprocessor/repetition/enum_params.hpp>
0032 #include <boost/preprocessor/cat.hpp>
0033 #include <boost/preprocessor/iteration/local.hpp>
0034 #include <boost/preprocessor/arithmetic/inc.hpp>
0035
0036 #endif
0037
0038 namespace boost
0039 {
0040 namespace assign_detail
0041 {
0042 template< class T >
0043 struct repeater
0044 {
0045 std::size_t sz;
0046 T val;
0047
0048 repeater( std::size_t sz_, T r ) : sz( sz_ ), val( r )
0049 { }
0050 };
0051
0052 template< class Fun >
0053 struct fun_repeater
0054 {
0055 std::size_t sz;
0056 Fun val;
0057
0058 fun_repeater( std::size_t sz_, Fun r ) : sz( sz_ ), val( r )
0059 { }
0060 };
0061
0062
0063 template< class T >
0064 struct is_repeater : boost::false_type {};
0065
0066 template< class T >
0067 struct is_repeater< boost::assign_detail::repeater<T> > : boost::true_type{};
0068
0069 template< class Fun >
0070 struct is_repeater< boost::assign_detail::fun_repeater<Fun> > : boost::true_type{};
0071
0072
0073 template< class C >
0074 class call_push_back
0075 {
0076 C& c_;
0077 public:
0078 call_push_back( C& c ) : c_( c )
0079 { }
0080
0081 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0082 template< class T >
0083 void operator()( T r )
0084 {
0085 c_.push_back( r );
0086 }
0087 #else
0088 template< class T >
0089 void operator()(T&& r)
0090 {
0091 c_.push_back(boost::forward<T>(r));
0092 }
0093 #endif
0094 };
0095
0096 template< class C >
0097 class call_push_front
0098 {
0099 C& c_;
0100 public:
0101 call_push_front( C& c ) : c_( c )
0102 { }
0103
0104 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0105 template< class T >
0106 void operator()( T r )
0107 {
0108 c_.push_front( r );
0109 }
0110 #else
0111 template< class T >
0112 void operator()(T&& r)
0113 {
0114 c_.push_front(boost::forward<T>(r));
0115 }
0116 #endif
0117 };
0118
0119 template< class C >
0120 class call_push
0121 {
0122 C& c_;
0123 public:
0124 call_push( C& c ) : c_( c )
0125 { }
0126
0127 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0128 template< class T >
0129 void operator()( T r )
0130 {
0131 c_.push( r );
0132 }
0133 #else
0134 template< class T >
0135 void operator()(T&& r)
0136 {
0137 c_.push(boost::forward<T>(r));
0138 }
0139 #endif
0140 };
0141
0142 template< class C >
0143 class call_insert
0144 {
0145 C& c_;
0146 public:
0147 call_insert( C& c ) : c_( c )
0148 { }
0149
0150 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0151 template< class T >
0152 void operator()( T r )
0153 {
0154 c_.insert( r );
0155 }
0156 #else
0157 template< class T >
0158 void operator()(T&& r)
0159 {
0160 c_.insert(boost::forward<T>(r));
0161 }
0162 #endif
0163 };
0164
0165 template< class C >
0166 class call_add_edge
0167 {
0168 C& c_;
0169 public:
0170 call_add_edge( C& c ) : c_(c)
0171 { }
0172
0173 template< class T >
0174 void operator()( T l, T r )
0175 {
0176 add_edge( l, r, c_ );
0177 }
0178
0179 template< class T, class EP >
0180 void operator()( T l, T r, const EP& ep )
0181 {
0182 add_edge( l, r, ep, c_ );
0183 }
0184
0185 };
0186
0187 struct forward_n_arguments {};
0188
0189 }
0190
0191 namespace assign
0192 {
0193
0194 template< class T >
0195 inline assign_detail::repeater<T>
0196 repeat( std::size_t sz, T r )
0197 {
0198 return assign_detail::repeater<T>( sz, r );
0199 }
0200
0201 template< class Function >
0202 inline assign_detail::fun_repeater<Function>
0203 repeat_fun( std::size_t sz, Function r )
0204 {
0205 return assign_detail::fun_repeater<Function>( sz, r );
0206 }
0207
0208
0209 template< class Function, class Argument = assign_detail::forward_n_arguments >
0210 class list_inserter
0211 {
0212 struct single_arg_type {};
0213 struct n_arg_type {};
0214 struct repeater_arg_type {};
0215
0216 typedef BOOST_DEDUCED_TYPENAME ::boost::conditional<
0217 is_same<Argument,assign_detail::forward_n_arguments>::value,
0218 n_arg_type,
0219 single_arg_type >::type arg_type;
0220
0221 public:
0222
0223 list_inserter( Function fun ) : insert_( fun )
0224 {}
0225
0226 template< class Function2, class Arg >
0227 list_inserter( const list_inserter<Function2,Arg>& r )
0228 : insert_( r.fun_private() )
0229 {}
0230
0231 list_inserter( const list_inserter& r ) : insert_( r.insert_ )
0232 {}
0233
0234 list_inserter& operator()()
0235 {
0236 insert_( Argument() );
0237 return *this;
0238 }
0239
0240 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0241 template< class T >
0242 list_inserter& operator=( const T& r )
0243 {
0244 insert_( r );
0245 return *this;
0246 }
0247
0248 template< class T >
0249 list_inserter& operator=( assign_detail::repeater<T> r )
0250 {
0251 return operator,( r );
0252 }
0253
0254 template< class Nullary_function >
0255 list_inserter& operator=( const assign_detail::fun_repeater<Nullary_function>& r )
0256 {
0257 return operator,( r );
0258 }
0259
0260 template< class T >
0261 list_inserter& operator,( const T& r )
0262 {
0263 insert_( r );
0264 return *this;
0265 }
0266
0267 #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205))
0268 template< class T >
0269 list_inserter& operator,( const assign_detail::repeater<T> & r )
0270 {
0271 return repeat( r.sz, r.val );
0272 }
0273 #else
0274 template< class T >
0275 list_inserter& operator,( assign_detail::repeater<T> r )
0276 {
0277 return repeat( r.sz, r.val );
0278 }
0279 #endif
0280
0281 template< class Nullary_function >
0282 list_inserter& operator,( const assign_detail::fun_repeater<Nullary_function>& r )
0283 {
0284 return repeat_fun( r.sz, r.val );
0285 }
0286 #else
0287
0288 template< class T >
0289 list_inserter& operator=(T&& r)
0290 {
0291 return operator,(boost::forward<T>(r));
0292 }
0293 #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
0294 template< class T >
0295 list_inserter& operator,(T&& r)
0296 {
0297 typedef BOOST_DEDUCED_TYPENAME ::boost::conditional<
0298 assign_detail::is_repeater< T >::value,
0299 repeater_arg_type,
0300 arg_type >::type tag;
0301
0302 insert(boost::forward<T>(r), tag());
0303 return *this;
0304 }
0305 #else
0306
0307 template< class T >
0308 list_inserter& operator,(T&& r)
0309 {
0310 typedef BOOST_DEDUCED_TYPENAME ::boost::conditional<
0311 assign_detail::is_repeater< T >::value,
0312 repeater_arg_type,
0313 arg_type >::type tag;
0314
0315 insert(tag(), boost::forward<T>(r));
0316 return *this;
0317 }
0318 #endif
0319 #endif
0320
0321 template< class T >
0322 list_inserter& repeat( std::size_t sz, T r )
0323 {
0324 std::size_t i = 0;
0325 while( i++ != sz )
0326 insert_( r );
0327 return *this;
0328 }
0329
0330 template< class Nullary_function >
0331 list_inserter& repeat_fun( std::size_t sz, Nullary_function fun )
0332 {
0333 std::size_t i = 0;
0334 while( i++ != sz )
0335 insert_( fun() );
0336 return *this;
0337 }
0338
0339 template< class SinglePassIterator >
0340 list_inserter& range( SinglePassIterator first,
0341 SinglePassIterator last )
0342 {
0343 for( ; first != last; ++first )
0344 insert_( *first );
0345 return *this;
0346 }
0347
0348 template< class SinglePassRange >
0349 list_inserter& range( const SinglePassRange& r )
0350 {
0351 return range( boost::begin(r), boost::end(r) );
0352 }
0353
0354 #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0355 template< class T >
0356 list_inserter& operator()( const T& t )
0357 {
0358 insert_( t );
0359 return *this;
0360 }
0361
0362 #ifndef BOOST_ASSIGN_MAX_PARAMS
0363 #define BOOST_ASSIGN_MAX_PARAMS 5
0364 #endif
0365 #define BOOST_ASSIGN_MAX_PARAMETERS (BOOST_ASSIGN_MAX_PARAMS - 1)
0366 #define BOOST_ASSIGN_PARAMS1(n) BOOST_PP_ENUM_PARAMS(n, class T)
0367 #define BOOST_ASSIGN_PARAMS2(n) BOOST_PP_ENUM_BINARY_PARAMS(n, T, const& t)
0368 #define BOOST_ASSIGN_PARAMS3(n) BOOST_PP_ENUM_PARAMS(n, t)
0369
0370 #define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS)
0371 #define BOOST_PP_LOCAL_MACRO(n) \
0372 template< class T, BOOST_ASSIGN_PARAMS1(n) > \
0373 list_inserter& operator()(T t, BOOST_ASSIGN_PARAMS2(n) ) \
0374 { \
0375 BOOST_PP_CAT(insert, BOOST_PP_INC(n))(t, BOOST_ASSIGN_PARAMS3(n), arg_type()); \
0376 return *this; \
0377 } \
0378
0379
0380 #include BOOST_PP_LOCAL_ITERATE()
0381
0382
0383 #define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS)
0384 #define BOOST_PP_LOCAL_MACRO(n) \
0385 template< class T, BOOST_ASSIGN_PARAMS1(n) > \
0386 void BOOST_PP_CAT(insert, BOOST_PP_INC(n))(T const& t, BOOST_ASSIGN_PARAMS2(n), single_arg_type) \
0387 { \
0388 insert_( Argument(t, BOOST_ASSIGN_PARAMS3(n) )); \
0389 } \
0390
0391
0392 #include BOOST_PP_LOCAL_ITERATE()
0393
0394 #define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS)
0395 #define BOOST_PP_LOCAL_MACRO(n) \
0396 template< class T, BOOST_ASSIGN_PARAMS1(n) > \
0397 void BOOST_PP_CAT(insert, BOOST_PP_INC(n))(T const& t, BOOST_ASSIGN_PARAMS2(n), n_arg_type) \
0398 { \
0399 insert_(t, BOOST_ASSIGN_PARAMS3(n) ); \
0400 } \
0401
0402
0403 #include BOOST_PP_LOCAL_ITERATE()
0404
0405 #else
0406 template< class... Ts >
0407 list_inserter& operator()(Ts&&... ts)
0408 {
0409 insert(arg_type(), boost::forward<Ts>(ts)...);
0410 return *this;
0411 }
0412
0413 template< class T >
0414 void insert(single_arg_type, T&& t)
0415 {
0416
0417 insert_(boost::forward<T>(t));
0418 }
0419
0420 template< class T1, class T2, class... Ts >
0421 void insert(single_arg_type, T1&& t1, T2&& t2, Ts&&... ts)
0422 {
0423 insert_(Argument(boost::forward<T1>(t1), boost::forward<T2>(t2), boost::forward<Ts>(ts)...));
0424 }
0425
0426 template< class... Ts >
0427 void insert(n_arg_type, Ts&&... ts)
0428 {
0429 insert_(boost::forward<Ts>(ts)...);
0430 }
0431
0432 #endif
0433
0434 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0435
0436 #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
0437
0438 template< class T >
0439 void insert( T&& r, arg_type)
0440 {
0441 insert_( boost::forward<T>(r) );
0442 }
0443
0444 template< class T >
0445 void insert(assign_detail::repeater<T> r, repeater_arg_type)
0446 {
0447 repeat(r.sz, r.val);
0448 }
0449
0450 template< class Nullary_function >
0451 void insert(const assign_detail::fun_repeater<Nullary_function>& r, repeater_arg_type)
0452 {
0453 repeat_fun(r.sz, r.val);
0454 }
0455 #else
0456 template< class T >
0457 void insert(repeater_arg_type, assign_detail::repeater<T> r)
0458 {
0459 repeat(r.sz, r.val);
0460 }
0461
0462 template< class Nullary_function >
0463 void insert(repeater_arg_type, const assign_detail::fun_repeater<Nullary_function>& r)
0464 {
0465 repeat_fun(r.sz, r.val);
0466 }
0467 #endif
0468 #endif
0469
0470
0471 Function fun_private() const
0472 {
0473 return insert_;
0474 }
0475
0476 private:
0477
0478 list_inserter& operator=( const list_inserter& );
0479 Function insert_;
0480 };
0481
0482 template< class Function >
0483 inline list_inserter< Function >
0484 make_list_inserter( Function fun )
0485 {
0486 return list_inserter< Function >( fun );
0487 }
0488
0489 template< class Function, class Argument >
0490 inline list_inserter<Function,Argument>
0491 make_list_inserter( Function fun, Argument* )
0492 {
0493 return list_inserter<Function,Argument>( fun );
0494 }
0495
0496 template< class C >
0497 inline list_inserter< assign_detail::call_push_back<C>,
0498 BOOST_DEDUCED_TYPENAME C::value_type >
0499 push_back( C& c )
0500 {
0501 static BOOST_DEDUCED_TYPENAME C::value_type* p = 0;
0502 return make_list_inserter( assign_detail::call_push_back<C>( c ),
0503 p );
0504 }
0505
0506 template< class C >
0507 inline list_inserter< assign_detail::call_push_front<C>,
0508 BOOST_DEDUCED_TYPENAME C::value_type >
0509 push_front( C& c )
0510 {
0511 static BOOST_DEDUCED_TYPENAME C::value_type* p = 0;
0512 return make_list_inserter( assign_detail::call_push_front<C>( c ),
0513 p );
0514 }
0515
0516 template< class C >
0517 inline list_inserter< assign_detail::call_insert<C>,
0518 BOOST_DEDUCED_TYPENAME C::value_type >
0519 insert( C& c )
0520 {
0521 static BOOST_DEDUCED_TYPENAME C::value_type* p = 0;
0522 return make_list_inserter( assign_detail::call_insert<C>( c ),
0523 p );
0524 }
0525
0526 template< class C >
0527 inline list_inserter< assign_detail::call_push<C>,
0528 BOOST_DEDUCED_TYPENAME C::value_type >
0529 push( C& c )
0530 {
0531 static BOOST_DEDUCED_TYPENAME C::value_type* p = 0;
0532 return make_list_inserter( assign_detail::call_push<C>( c ),
0533 p );
0534 }
0535
0536 template< class C >
0537 inline list_inserter< assign_detail::call_add_edge<C> >
0538 add_edge( C& c )
0539 {
0540 return make_list_inserter( assign_detail::call_add_edge<C>( c ) );
0541 }
0542
0543 }
0544 }
0545
0546 #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0547
0548 #undef BOOST_ASSIGN_PARAMS1
0549 #undef BOOST_ASSIGN_PARAMS2
0550 #undef BOOST_ASSIGN_PARAMS3
0551 #undef BOOST_ASSIGN_MAX_PARAMETERS
0552
0553 #endif
0554
0555 #endif