1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/stdapis/boost/assign/list_inserter.hpp Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -0,0 +1,404 @@
1.4 +// Boost.Assign library
1.5 +//
1.6 +// Copyright Thorsten Ottosen 2003-2004. Use, modification and
1.7 +// distribution is subject to the Boost Software License, Version
1.8 +// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
1.9 +// http://www.boost.org/LICENSE_1_0.txt)
1.10 +//
1.11 +// For more information, see http://www.boost.org/libs/assign/
1.12 +//
1.13 +
1.14 +#ifndef BOOST_ASSIGN_LIST_INSERTER_HPP
1.15 +#define BOOST_ASSIGN_LIST_INSERTER_HPP
1.16 +
1.17 +#if defined(_MSC_VER) && (_MSC_VER >= 1020)
1.18 +# pragma once
1.19 +#endif
1.20 +
1.21 +#include <boost/detail/workaround.hpp>
1.22 +
1.23 +#include <boost/mpl/if.hpp>
1.24 +#include <boost/type_traits/is_same.hpp>
1.25 +#include <boost/range/begin.hpp>
1.26 +#include <boost/range/end.hpp>
1.27 +#include <boost/config.hpp>
1.28 +#include <cstddef>
1.29 +
1.30 +#include <boost/preprocessor/repetition/enum_binary_params.hpp>
1.31 +#include <boost/preprocessor/repetition/enum_params.hpp>
1.32 +#include <boost/preprocessor/cat.hpp>
1.33 +#include <boost/preprocessor/iteration/local.hpp>
1.34 +#include <boost/preprocessor/arithmetic/inc.hpp>
1.35 +
1.36 +namespace boost
1.37 +{
1.38 +namespace assign_detail
1.39 +{
1.40 + template< class T >
1.41 + struct repeater
1.42 + {
1.43 + std::size_t sz;
1.44 + T val;
1.45 +
1.46 + repeater( std::size_t sz, T r ) : sz( sz ), val( r )
1.47 + { }
1.48 + };
1.49 +
1.50 + template< class Fun >
1.51 + struct fun_repeater
1.52 + {
1.53 + std::size_t sz;
1.54 + Fun val;
1.55 +
1.56 + fun_repeater( std::size_t sz, Fun r ) : sz( sz ), val( r )
1.57 + { }
1.58 + };
1.59 +
1.60 + template< class C >
1.61 + class call_push_back
1.62 + {
1.63 + C& c_;
1.64 + public:
1.65 + call_push_back( C& c ) : c_( c )
1.66 + { }
1.67 +
1.68 + template< class T >
1.69 + void operator()( T r )
1.70 + {
1.71 + c_.push_back( r );
1.72 + }
1.73 + };
1.74 +
1.75 + template< class C >
1.76 + class call_push_front
1.77 + {
1.78 + C& c_;
1.79 + public:
1.80 + call_push_front( C& c ) : c_( c )
1.81 + { }
1.82 +
1.83 + template< class T >
1.84 + void operator()( T r )
1.85 + {
1.86 + c_.push_front( r );
1.87 + }
1.88 + };
1.89 +
1.90 + template< class C >
1.91 + class call_push
1.92 + {
1.93 + C& c_;
1.94 + public:
1.95 + call_push( C& c ) : c_( c )
1.96 + { }
1.97 +
1.98 + template< class T >
1.99 + void operator()( T r )
1.100 + {
1.101 + c_.push( r );
1.102 + }
1.103 + };
1.104 +
1.105 + template< class C >
1.106 + class call_insert
1.107 + {
1.108 + C& c_;
1.109 + public:
1.110 + call_insert( C& c ) : c_( c )
1.111 + { }
1.112 +
1.113 + template< class T >
1.114 + void operator()( T r )
1.115 + {
1.116 + c_.insert( r );
1.117 + }
1.118 + };
1.119 +
1.120 + template< class C >
1.121 + class call_add_edge
1.122 + {
1.123 + C& c_;
1.124 + public:
1.125 + call_add_edge( C& c ) : c_(c)
1.126 + { }
1.127 +
1.128 + template< class T >
1.129 + void operator()( T l, T r )
1.130 + {
1.131 + add_edge( l, r, c_ );
1.132 + }
1.133 +
1.134 + template< class T, class EP >
1.135 + void operator()( T l, T r, const EP& ep )
1.136 + {
1.137 + add_edge( l, r, ep, c_ );
1.138 + }
1.139 +
1.140 + };
1.141 +
1.142 + struct forward_n_arguments {};
1.143 +
1.144 +} // namespace 'assign_detail'
1.145 +
1.146 +namespace assign
1.147 +{
1.148 +
1.149 + template< class T >
1.150 + inline assign_detail::repeater<T>
1.151 + repeat( std::size_t sz, T r )
1.152 + {
1.153 + return assign_detail::repeater<T>( sz, r );
1.154 + }
1.155 +
1.156 + template< class Function >
1.157 + inline assign_detail::fun_repeater<Function>
1.158 + repeat_fun( std::size_t sz, Function r )
1.159 + {
1.160 + return assign_detail::fun_repeater<Function>( sz, r );
1.161 + }
1.162 +
1.163 +
1.164 + template< class Function, class Argument = assign_detail::forward_n_arguments >
1.165 + class list_inserter
1.166 + {
1.167 + struct single_arg_type {};
1.168 + struct n_arg_type {};
1.169 +
1.170 + typedef BOOST_DEDUCED_TYPENAME mpl::if_c< is_same<Argument,assign_detail::forward_n_arguments>::value,
1.171 + n_arg_type,
1.172 + single_arg_type >::type arg_type;
1.173 +
1.174 + public:
1.175 +
1.176 + list_inserter( Function fun ) : insert_( fun )
1.177 + {}
1.178 +
1.179 + template< class Function2, class Arg >
1.180 + list_inserter( const list_inserter<Function2,Arg>& r )
1.181 + : insert_( r.fun_private() )
1.182 + {}
1.183 +
1.184 + list_inserter( const list_inserter& r ) : insert_( r.insert_ )
1.185 + {}
1.186 +
1.187 + list_inserter& operator()()
1.188 + {
1.189 + insert_( Argument() );
1.190 + return *this;
1.191 + }
1.192 +
1.193 + template< class T >
1.194 + list_inserter& operator=( const T& r )
1.195 + {
1.196 + insert_( r );
1.197 + return *this;
1.198 + }
1.199 +
1.200 + template< class T >
1.201 + list_inserter& operator=( assign_detail::repeater<T> r )
1.202 + {
1.203 + return operator,( r );
1.204 + }
1.205 +
1.206 + template< class Nullary_function >
1.207 + list_inserter& operator=( const assign_detail::fun_repeater<Nullary_function>& r )
1.208 + {
1.209 + //BOOST_STATIC_ASSERT( function_traits<Nullary_function>::arity == 0 );
1.210 + //BOOST_STATIC_ASSERT( is_convertible< BOOST_DEDUCED_TYPENAME function_traits<
1.211 + // Nullary_function>::result_type >,T>::value );
1.212 +
1.213 + return operator,( r );
1.214 + }
1.215 +
1.216 + template< class T >
1.217 + list_inserter& operator,( const T& r )
1.218 + {
1.219 + insert_( r );
1.220 + return *this;
1.221 + }
1.222 +
1.223 +#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205))
1.224 + template< class T >
1.225 + list_inserter& operator,( const assign_detail::repeater<T> & r )
1.226 + {
1.227 + return repeat( r.sz, r.val );
1.228 + }
1.229 +#else
1.230 + template< class T >
1.231 + list_inserter& operator,( assign_detail::repeater<T> r )
1.232 + {
1.233 + return repeat( r.sz, r.val );
1.234 + }
1.235 +#endif
1.236 +
1.237 + template< class Nullary_function >
1.238 + list_inserter& operator,( const assign_detail::fun_repeater<Nullary_function>& r )
1.239 + {
1.240 + return repeat_fun( r.sz, r.val );
1.241 + }
1.242 +
1.243 + template< class T >
1.244 + list_inserter& repeat( std::size_t sz, T r )
1.245 + {
1.246 + std::size_t i = 0;
1.247 + while( i++ != sz )
1.248 + insert_( r );
1.249 + return *this;
1.250 + }
1.251 +
1.252 + template< class Nullary_function >
1.253 + list_inserter& repeat_fun( std::size_t sz, Nullary_function fun )
1.254 + {
1.255 + std::size_t i = 0;
1.256 + while( i++ != sz )
1.257 + insert_( fun() );
1.258 + return *this;
1.259 + }
1.260 +
1.261 + template< class SinglePassIterator >
1.262 + list_inserter& range( SinglePassIterator first,
1.263 + SinglePassIterator last )
1.264 + {
1.265 + for( ; first != last; ++first )
1.266 + insert_( *first );
1.267 + return *this;
1.268 + }
1.269 +
1.270 + template< class SinglePassRange >
1.271 + list_inserter& range( const SinglePassRange& r )
1.272 + {
1.273 + return range( boost::begin(r), boost::end(r) );
1.274 + }
1.275 +
1.276 + template< class T >
1.277 + list_inserter& operator()( const T& t )
1.278 + {
1.279 + insert_( t );
1.280 + return *this;
1.281 + }
1.282 +
1.283 +#ifndef BOOST_ASSIGN_MAX_PARAMS // use user's value
1.284 +#define BOOST_ASSIGN_MAX_PARAMS 5
1.285 +#endif
1.286 +#define BOOST_ASSIGN_MAX_PARAMETERS (BOOST_ASSIGN_MAX_PARAMS - 1)
1.287 +#define BOOST_ASSIGN_PARAMS1(n) BOOST_PP_ENUM_PARAMS(n, class T)
1.288 +#define BOOST_ASSIGN_PARAMS2(n) BOOST_PP_ENUM_BINARY_PARAMS(n, T, const& t)
1.289 +#define BOOST_ASSIGN_PARAMS3(n) BOOST_PP_ENUM_PARAMS(n, t)
1.290 +
1.291 +#define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS)
1.292 +#define BOOST_PP_LOCAL_MACRO(n) \
1.293 + template< class T, BOOST_ASSIGN_PARAMS1(n) > \
1.294 + list_inserter& operator()(T t, BOOST_ASSIGN_PARAMS2(n) ) \
1.295 + { \
1.296 + BOOST_PP_CAT(insert, BOOST_PP_INC(n))(t, BOOST_ASSIGN_PARAMS3(n), arg_type()); \
1.297 + return *this; \
1.298 + } \
1.299 + /**/
1.300 +
1.301 +#include BOOST_PP_LOCAL_ITERATE()
1.302 +
1.303 +
1.304 +#define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS)
1.305 +#define BOOST_PP_LOCAL_MACRO(n) \
1.306 + template< class T, BOOST_ASSIGN_PARAMS1(n) > \
1.307 + void BOOST_PP_CAT(insert, BOOST_PP_INC(n))(T const& t, BOOST_ASSIGN_PARAMS2(n), single_arg_type) \
1.308 + { \
1.309 + insert_( Argument(t, BOOST_ASSIGN_PARAMS3(n) )); \
1.310 + } \
1.311 + /**/
1.312 +
1.313 +#include BOOST_PP_LOCAL_ITERATE()
1.314 +
1.315 +#define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS)
1.316 +#define BOOST_PP_LOCAL_MACRO(n) \
1.317 + template< class T, BOOST_ASSIGN_PARAMS1(n) > \
1.318 + void BOOST_PP_CAT(insert, BOOST_PP_INC(n))(T const& t, BOOST_ASSIGN_PARAMS2(n), n_arg_type) \
1.319 + { \
1.320 + insert_(t, BOOST_ASSIGN_PARAMS3(n) ); \
1.321 + } \
1.322 + /**/
1.323 +
1.324 +#include BOOST_PP_LOCAL_ITERATE()
1.325 +
1.326 +
1.327 + Function fun_private() const
1.328 + {
1.329 + return insert_;
1.330 + }
1.331 +
1.332 + private:
1.333 +
1.334 + list_inserter& operator=( const list_inserter& );
1.335 + Function insert_;
1.336 + };
1.337 +
1.338 + template< class Function >
1.339 + inline list_inserter< Function >
1.340 + make_list_inserter( Function fun )
1.341 + {
1.342 + return list_inserter< Function >( fun );
1.343 + }
1.344 +
1.345 + template< class Function, class Argument >
1.346 + inline list_inserter<Function,Argument>
1.347 + make_list_inserter( Function fun, Argument* )
1.348 + {
1.349 + return list_inserter<Function,Argument>( fun );
1.350 + }
1.351 +
1.352 + template< class C >
1.353 + inline list_inserter< assign_detail::call_push_back<C>,
1.354 + BOOST_DEDUCED_TYPENAME C::value_type >
1.355 + push_back( C& c )
1.356 + {
1.357 + static BOOST_DEDUCED_TYPENAME C::value_type* p = 0;
1.358 + return make_list_inserter( assign_detail::call_push_back<C>( c ),
1.359 + p );
1.360 + }
1.361 +
1.362 + template< class C >
1.363 + inline list_inserter< assign_detail::call_push_front<C>,
1.364 + BOOST_DEDUCED_TYPENAME C::value_type >
1.365 + push_front( C& c )
1.366 + {
1.367 + static BOOST_DEDUCED_TYPENAME C::value_type* p = 0;
1.368 + return make_list_inserter( assign_detail::call_push_front<C>( c ),
1.369 + p );
1.370 + }
1.371 +
1.372 + template< class C >
1.373 + inline list_inserter< assign_detail::call_insert<C>,
1.374 + BOOST_DEDUCED_TYPENAME C::value_type >
1.375 + insert( C& c )
1.376 + {
1.377 + static BOOST_DEDUCED_TYPENAME C::value_type* p = 0;
1.378 + return make_list_inserter( assign_detail::call_insert<C>( c ),
1.379 + p );
1.380 + }
1.381 +
1.382 + template< class C >
1.383 + inline list_inserter< assign_detail::call_push<C>,
1.384 + BOOST_DEDUCED_TYPENAME C::value_type >
1.385 + push( C& c )
1.386 + {
1.387 + static BOOST_DEDUCED_TYPENAME C::value_type* p = 0;
1.388 + return make_list_inserter( assign_detail::call_push<C>( c ),
1.389 + p );
1.390 + }
1.391 +
1.392 + template< class C >
1.393 + inline list_inserter< assign_detail::call_add_edge<C> >
1.394 + add_edge( C& c )
1.395 + {
1.396 + return make_list_inserter( assign_detail::call_add_edge<C>( c ) );
1.397 + }
1.398 +
1.399 +} // namespace 'assign'
1.400 +} // namespace 'boost'
1.401 +
1.402 +#undef BOOST_ASSIGN_PARAMS1
1.403 +#undef BOOST_ASSIGN_PARAMS2
1.404 +#undef BOOST_ASSIGN_PARAMS3
1.405 +#undef BOOST_ASSIGN_MAX_PARAMETERS
1.406 +
1.407 +#endif