Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / assign / list_inserter.hpp @ 2486

History | View | Annotate | Download (10.3 kB)

1 2486 sjacqu01
// Boost.Assign library
2 2486 sjacqu01
//
3 2486 sjacqu01
//  Copyright Thorsten Ottosen 2003-2004. Use, modification and
4 2486 sjacqu01
//  distribution is subject to the Boost Software License, Version
5 2486 sjacqu01
//  1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 2486 sjacqu01
//  http://www.boost.org/LICENSE_1_0.txt)
7 2486 sjacqu01
//
8 2486 sjacqu01
// For more information, see http://www.boost.org/libs/assign/
9 2486 sjacqu01
//
10 2486 sjacqu01
11 2486 sjacqu01
#ifndef BOOST_ASSIGN_LIST_INSERTER_HPP
12 2486 sjacqu01
#define BOOST_ASSIGN_LIST_INSERTER_HPP
13 2486 sjacqu01
14 2486 sjacqu01
#if defined(_MSC_VER)
15 2486 sjacqu01
# pragma once
16 2486 sjacqu01
#endif
17 2486 sjacqu01
18 2486 sjacqu01
#include <boost/detail/workaround.hpp>
19 2486 sjacqu01
20 2486 sjacqu01
#include <boost/mpl/if.hpp>
21 2486 sjacqu01
#include <boost/type_traits/is_same.hpp>
22 2486 sjacqu01
#include <boost/range/begin.hpp>
23 2486 sjacqu01
#include <boost/range/end.hpp>
24 2486 sjacqu01
#include <boost/config.hpp>
25 2486 sjacqu01
#include <cstddef>
26 2486 sjacqu01
27 2486 sjacqu01
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
28 2486 sjacqu01
#include <boost/preprocessor/repetition/enum_params.hpp>
29 2486 sjacqu01
#include <boost/preprocessor/cat.hpp>
30 2486 sjacqu01
#include <boost/preprocessor/iteration/local.hpp>
31 2486 sjacqu01
#include <boost/preprocessor/arithmetic/inc.hpp>
32 2486 sjacqu01
33 2486 sjacqu01
namespace boost
34 2486 sjacqu01
{
35 2486 sjacqu01
namespace assign_detail
36 2486 sjacqu01
{
37 2486 sjacqu01
    template< class T >
38 2486 sjacqu01
    struct repeater
39 2486 sjacqu01
    {
40 2486 sjacqu01
        std::size_t  sz;
41 2486 sjacqu01
        T            val;
42 2486 sjacqu01
43 2486 sjacqu01
        repeater( std::size_t sz_, T r ) : sz( sz_ ), val( r )
44 2486 sjacqu01
        { }
45 2486 sjacqu01
    };
46 2486 sjacqu01
47 2486 sjacqu01
    template< class Fun >
48 2486 sjacqu01
    struct fun_repeater
49 2486 sjacqu01
    {
50 2486 sjacqu01
        std::size_t  sz;
51 2486 sjacqu01
        Fun          val;
52 2486 sjacqu01
53 2486 sjacqu01
        fun_repeater( std::size_t sz_, Fun r ) : sz( sz_ ), val( r )
54 2486 sjacqu01
        { }
55 2486 sjacqu01
    };
56 2486 sjacqu01
57 2486 sjacqu01
    template< class C >
58 2486 sjacqu01
    class call_push_back
59 2486 sjacqu01
    {
60 2486 sjacqu01
        C& c_;
61 2486 sjacqu01
    public:
62 2486 sjacqu01
        call_push_back( C& c ) : c_( c )
63 2486 sjacqu01
        { }
64 2486 sjacqu01
65 2486 sjacqu01
        template< class T >
66 2486 sjacqu01
        void operator()( T r )
67 2486 sjacqu01
        {
68 2486 sjacqu01
            c_.push_back( r );
69 2486 sjacqu01
        }
70 2486 sjacqu01
    };
71 2486 sjacqu01
72 2486 sjacqu01
    template< class C >
73 2486 sjacqu01
    class call_push_front
74 2486 sjacqu01
    {
75 2486 sjacqu01
        C& c_;
76 2486 sjacqu01
    public:
77 2486 sjacqu01
        call_push_front( C& c ) : c_( c )
78 2486 sjacqu01
        { }
79 2486 sjacqu01
80 2486 sjacqu01
        template< class T >
81 2486 sjacqu01
        void operator()( T r )
82 2486 sjacqu01
        {
83 2486 sjacqu01
            c_.push_front( r );
84 2486 sjacqu01
        }
85 2486 sjacqu01
    };
86 2486 sjacqu01
87 2486 sjacqu01
    template< class C >
88 2486 sjacqu01
    class call_push
89 2486 sjacqu01
    {
90 2486 sjacqu01
        C& c_;
91 2486 sjacqu01
    public:
92 2486 sjacqu01
        call_push( C& c ) : c_( c )
93 2486 sjacqu01
        { }
94 2486 sjacqu01
95 2486 sjacqu01
        template< class T >
96 2486 sjacqu01
        void operator()( T r )
97 2486 sjacqu01
        {
98 2486 sjacqu01
            c_.push( r );
99 2486 sjacqu01
        }
100 2486 sjacqu01
    };
101 2486 sjacqu01
102 2486 sjacqu01
    template< class C >
103 2486 sjacqu01
    class call_insert
104 2486 sjacqu01
    {
105 2486 sjacqu01
        C& c_;
106 2486 sjacqu01
    public:
107 2486 sjacqu01
        call_insert( C& c ) : c_( c )
108 2486 sjacqu01
        { }
109 2486 sjacqu01
110 2486 sjacqu01
        template< class T >
111 2486 sjacqu01
        void operator()( T r )
112 2486 sjacqu01
        {
113 2486 sjacqu01
            c_.insert( r );
114 2486 sjacqu01
        }
115 2486 sjacqu01
    };
116 2486 sjacqu01
117 2486 sjacqu01
    template< class C >
118 2486 sjacqu01
    class call_add_edge
119 2486 sjacqu01
    {
120 2486 sjacqu01
        C& c_;
121 2486 sjacqu01
    public:
122 2486 sjacqu01
        call_add_edge( C& c ) : c_(c)
123 2486 sjacqu01
        { }
124 2486 sjacqu01
125 2486 sjacqu01
        template< class T >
126 2486 sjacqu01
        void operator()( T l, T r )
127 2486 sjacqu01
        {
128 2486 sjacqu01
            add_edge( l, r, c_ );
129 2486 sjacqu01
        }
130 2486 sjacqu01
131 2486 sjacqu01
        template< class T, class EP >
132 2486 sjacqu01
        void operator()( T l, T r, const EP& ep )
133 2486 sjacqu01
        {
134 2486 sjacqu01
            add_edge( l, r, ep, c_ );
135 2486 sjacqu01
        }
136 2486 sjacqu01
137 2486 sjacqu01
    };
138 2486 sjacqu01
139 2486 sjacqu01
    struct forward_n_arguments {};
140 2486 sjacqu01
141 2486 sjacqu01
} // namespace 'assign_detail'
142 2486 sjacqu01
143 2486 sjacqu01
namespace assign
144 2486 sjacqu01
{
145 2486 sjacqu01
146 2486 sjacqu01
    template< class T >
147 2486 sjacqu01
    inline assign_detail::repeater<T>
148 2486 sjacqu01
    repeat( std::size_t sz, T r )
149 2486 sjacqu01
    {
150 2486 sjacqu01
        return assign_detail::repeater<T>( sz, r );
151 2486 sjacqu01
    }
152 2486 sjacqu01
153 2486 sjacqu01
    template< class Function >
154 2486 sjacqu01
    inline assign_detail::fun_repeater<Function>
155 2486 sjacqu01
    repeat_fun( std::size_t sz, Function r )
156 2486 sjacqu01
    {
157 2486 sjacqu01
        return assign_detail::fun_repeater<Function>( sz, r );
158 2486 sjacqu01
    }
159 2486 sjacqu01
160 2486 sjacqu01
161 2486 sjacqu01
    template< class Function, class Argument = assign_detail::forward_n_arguments >
162 2486 sjacqu01
    class list_inserter
163 2486 sjacqu01
    {
164 2486 sjacqu01
        struct single_arg_type {};
165 2486 sjacqu01
        struct n_arg_type      {};
166 2486 sjacqu01
167 2486 sjacqu01
        typedef BOOST_DEDUCED_TYPENAME mpl::if_c< is_same<Argument,assign_detail::forward_n_arguments>::value,
168 2486 sjacqu01
                                                  n_arg_type,
169 2486 sjacqu01
                                                  single_arg_type >::type arg_type;
170 2486 sjacqu01
171 2486 sjacqu01
    public:
172 2486 sjacqu01
173 2486 sjacqu01
        list_inserter( Function fun ) : insert_( fun )
174 2486 sjacqu01
        {}
175 2486 sjacqu01
176 2486 sjacqu01
        template< class Function2, class Arg >
177 2486 sjacqu01
        list_inserter( const list_inserter<Function2,Arg>& r )
178 2486 sjacqu01
        : insert_( r.fun_private() )
179 2486 sjacqu01
        {}
180 2486 sjacqu01
181 2486 sjacqu01
        list_inserter( const list_inserter& r ) : insert_( r.insert_ )
182 2486 sjacqu01
        {}
183 2486 sjacqu01
184 2486 sjacqu01
        list_inserter& operator()()
185 2486 sjacqu01
        {
186 2486 sjacqu01
            insert_( Argument() );
187 2486 sjacqu01
            return *this;
188 2486 sjacqu01
        }
189 2486 sjacqu01
190 2486 sjacqu01
        template< class T >
191 2486 sjacqu01
        list_inserter& operator=( const T& r )
192 2486 sjacqu01
        {
193 2486 sjacqu01
            insert_( r );
194 2486 sjacqu01
            return *this;
195 2486 sjacqu01
        }
196 2486 sjacqu01
197 2486 sjacqu01
        template< class T >
198 2486 sjacqu01
        list_inserter& operator=( assign_detail::repeater<T> r )
199 2486 sjacqu01
        {
200 2486 sjacqu01
            return operator,( r );
201 2486 sjacqu01
        }
202 2486 sjacqu01
203 2486 sjacqu01
        template< class Nullary_function >
204 2486 sjacqu01
        list_inserter& operator=( const assign_detail::fun_repeater<Nullary_function>& r )
205 2486 sjacqu01
        {
206 2486 sjacqu01
            return operator,( r );
207 2486 sjacqu01
        }
208 2486 sjacqu01
209 2486 sjacqu01
        template< class T >
210 2486 sjacqu01
        list_inserter& operator,( const T& r )
211 2486 sjacqu01
        {
212 2486 sjacqu01
            insert_( r  );
213 2486 sjacqu01
            return *this;
214 2486 sjacqu01
        }
215 2486 sjacqu01
216 2486 sjacqu01
#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205))
217 2486 sjacqu01
        template< class T >
218 2486 sjacqu01
        list_inserter& operator,( const assign_detail::repeater<T> & r )
219 2486 sjacqu01
        {
220 2486 sjacqu01
            return repeat( r.sz, r.val );
221 2486 sjacqu01
        }
222 2486 sjacqu01
#else
223 2486 sjacqu01
        template< class T >
224 2486 sjacqu01
        list_inserter& operator,( assign_detail::repeater<T> r )
225 2486 sjacqu01
        {
226 2486 sjacqu01
            return repeat( r.sz, r.val );
227 2486 sjacqu01
        }
228 2486 sjacqu01
#endif
229 2486 sjacqu01
230 2486 sjacqu01
        template< class Nullary_function >
231 2486 sjacqu01
        list_inserter& operator,( const assign_detail::fun_repeater<Nullary_function>& r )
232 2486 sjacqu01
        {
233 2486 sjacqu01
            return repeat_fun( r.sz, r.val );
234 2486 sjacqu01
        }
235 2486 sjacqu01
236 2486 sjacqu01
        template< class T >
237 2486 sjacqu01
        list_inserter& repeat( std::size_t sz, T r )
238 2486 sjacqu01
        {
239 2486 sjacqu01
            std::size_t i = 0;
240 2486 sjacqu01
            while( i++ != sz )
241 2486 sjacqu01
                insert_( r );
242 2486 sjacqu01
            return *this;
243 2486 sjacqu01
        }
244 2486 sjacqu01
245 2486 sjacqu01
        template< class Nullary_function >
246 2486 sjacqu01
        list_inserter& repeat_fun( std::size_t sz, Nullary_function fun )
247 2486 sjacqu01
        {
248 2486 sjacqu01
            std::size_t i = 0;
249 2486 sjacqu01
            while( i++ != sz )
250 2486 sjacqu01
                insert_( fun() );
251 2486 sjacqu01
            return *this;
252 2486 sjacqu01
        }
253 2486 sjacqu01
254 2486 sjacqu01
        template< class SinglePassIterator >
255 2486 sjacqu01
        list_inserter& range( SinglePassIterator first,
256 2486 sjacqu01
                              SinglePassIterator last )
257 2486 sjacqu01
        {
258 2486 sjacqu01
            for( ; first != last; ++first )
259 2486 sjacqu01
                insert_( *first );
260 2486 sjacqu01
            return *this;
261 2486 sjacqu01
        }
262 2486 sjacqu01
263 2486 sjacqu01
        template< class SinglePassRange >
264 2486 sjacqu01
        list_inserter& range( const SinglePassRange& r )
265 2486 sjacqu01
        {
266 2486 sjacqu01
            return range( boost::begin(r), boost::end(r) );
267 2486 sjacqu01
        }
268 2486 sjacqu01
269 2486 sjacqu01
        template< class T >
270 2486 sjacqu01
        list_inserter& operator()( const T& t )
271 2486 sjacqu01
        {
272 2486 sjacqu01
            insert_( t );
273 2486 sjacqu01
            return *this;
274 2486 sjacqu01
        }
275 2486 sjacqu01
276 2486 sjacqu01
#ifndef BOOST_ASSIGN_MAX_PARAMS // use user's value
277 2486 sjacqu01
#define BOOST_ASSIGN_MAX_PARAMS 5
278 2486 sjacqu01
#endif
279 2486 sjacqu01
#define BOOST_ASSIGN_MAX_PARAMETERS (BOOST_ASSIGN_MAX_PARAMS - 1)
280 2486 sjacqu01
#define BOOST_ASSIGN_PARAMS1(n) BOOST_PP_ENUM_PARAMS(n, class T)
281 2486 sjacqu01
#define BOOST_ASSIGN_PARAMS2(n) BOOST_PP_ENUM_BINARY_PARAMS(n, T, const& t)
282 2486 sjacqu01
#define BOOST_ASSIGN_PARAMS3(n) BOOST_PP_ENUM_PARAMS(n, t)
283 2486 sjacqu01
284 2486 sjacqu01
#define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS)
285 2486 sjacqu01
#define BOOST_PP_LOCAL_MACRO(n) \
286 2486 sjacqu01
    template< class T, BOOST_ASSIGN_PARAMS1(n) > \
287 2486 sjacqu01
    list_inserter& operator()(T t, BOOST_ASSIGN_PARAMS2(n) ) \
288 2486 sjacqu01
        { \
289 2486 sjacqu01
            BOOST_PP_CAT(insert, BOOST_PP_INC(n))(t, BOOST_ASSIGN_PARAMS3(n), arg_type()); \
290 2486 sjacqu01
            return *this; \
291 2486 sjacqu01
        } \
292 2486 sjacqu01
        /**/
293 2486 sjacqu01
294 2486 sjacqu01
#include BOOST_PP_LOCAL_ITERATE()
295 2486 sjacqu01
296 2486 sjacqu01
297 2486 sjacqu01
#define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS)
298 2486 sjacqu01
#define BOOST_PP_LOCAL_MACRO(n) \
299 2486 sjacqu01
    template< class T, BOOST_ASSIGN_PARAMS1(n) > \
300 2486 sjacqu01
    void BOOST_PP_CAT(insert, BOOST_PP_INC(n))(T const& t, BOOST_ASSIGN_PARAMS2(n), single_arg_type) \
301 2486 sjacqu01
    { \
302 2486 sjacqu01
        insert_( Argument(t, BOOST_ASSIGN_PARAMS3(n) )); \
303 2486 sjacqu01
    } \
304 2486 sjacqu01
    /**/
305 2486 sjacqu01
306 2486 sjacqu01
#include BOOST_PP_LOCAL_ITERATE()
307 2486 sjacqu01
308 2486 sjacqu01
#define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS)
309 2486 sjacqu01
#define BOOST_PP_LOCAL_MACRO(n) \
310 2486 sjacqu01
    template< class T, BOOST_ASSIGN_PARAMS1(n) > \
311 2486 sjacqu01
    void BOOST_PP_CAT(insert, BOOST_PP_INC(n))(T const& t, BOOST_ASSIGN_PARAMS2(n), n_arg_type) \
312 2486 sjacqu01
    { \
313 2486 sjacqu01
        insert_(t, BOOST_ASSIGN_PARAMS3(n) ); \
314 2486 sjacqu01
    } \
315 2486 sjacqu01
    /**/
316 2486 sjacqu01
317 2486 sjacqu01
#include BOOST_PP_LOCAL_ITERATE()
318 2486 sjacqu01
319 2486 sjacqu01
320 2486 sjacqu01
        Function fun_private() const
321 2486 sjacqu01
        {
322 2486 sjacqu01
            return insert_;
323 2486 sjacqu01
        }
324 2486 sjacqu01
325 2486 sjacqu01
    private:
326 2486 sjacqu01
327 2486 sjacqu01
        list_inserter& operator=( const list_inserter& );
328 2486 sjacqu01
        Function insert_;
329 2486 sjacqu01
    };
330 2486 sjacqu01
331 2486 sjacqu01
    template< class Function >
332 2486 sjacqu01
    inline list_inserter< Function >
333 2486 sjacqu01
    make_list_inserter( Function fun )
334 2486 sjacqu01
    {
335 2486 sjacqu01
        return list_inserter< Function >( fun );
336 2486 sjacqu01
    }
337 2486 sjacqu01
338 2486 sjacqu01
    template< class Function, class Argument >
339 2486 sjacqu01
    inline list_inserter<Function,Argument>
340 2486 sjacqu01
    make_list_inserter( Function fun, Argument* )
341 2486 sjacqu01
    {
342 2486 sjacqu01
        return list_inserter<Function,Argument>( fun );
343 2486 sjacqu01
    }
344 2486 sjacqu01
345 2486 sjacqu01
    template< class C >
346 2486 sjacqu01
    inline list_inserter< assign_detail::call_push_back<C>,
347 2486 sjacqu01
                          BOOST_DEDUCED_TYPENAME C::value_type >
348 2486 sjacqu01
    push_back( C& c )
349 2486 sjacqu01
    {
350 2486 sjacqu01
        static BOOST_DEDUCED_TYPENAME C::value_type* p = 0;
351 2486 sjacqu01
        return make_list_inserter( assign_detail::call_push_back<C>( c ),
352 2486 sjacqu01
                                   p );
353 2486 sjacqu01
    }
354 2486 sjacqu01
355 2486 sjacqu01
    template< class C >
356 2486 sjacqu01
    inline list_inserter< assign_detail::call_push_front<C>,
357 2486 sjacqu01
                          BOOST_DEDUCED_TYPENAME C::value_type >
358 2486 sjacqu01
    push_front( C& c )
359 2486 sjacqu01
    {
360 2486 sjacqu01
        static BOOST_DEDUCED_TYPENAME C::value_type* p = 0;
361 2486 sjacqu01
        return make_list_inserter( assign_detail::call_push_front<C>( c ),
362 2486 sjacqu01
                                   p );
363 2486 sjacqu01
    }
364 2486 sjacqu01
365 2486 sjacqu01
    template< class C >
366 2486 sjacqu01
    inline list_inserter< assign_detail::call_insert<C>,
367 2486 sjacqu01
                          BOOST_DEDUCED_TYPENAME C::value_type >
368 2486 sjacqu01
    insert( C& c )
369 2486 sjacqu01
    {
370 2486 sjacqu01
        static BOOST_DEDUCED_TYPENAME C::value_type* p = 0;
371 2486 sjacqu01
        return make_list_inserter( assign_detail::call_insert<C>( c ),
372 2486 sjacqu01
                                   p );
373 2486 sjacqu01
    }
374 2486 sjacqu01
375 2486 sjacqu01
    template< class C >
376 2486 sjacqu01
    inline list_inserter< assign_detail::call_push<C>,
377 2486 sjacqu01
                          BOOST_DEDUCED_TYPENAME C::value_type >
378 2486 sjacqu01
    push( C& c )
379 2486 sjacqu01
    {
380 2486 sjacqu01
        static BOOST_DEDUCED_TYPENAME C::value_type* p = 0;
381 2486 sjacqu01
        return make_list_inserter( assign_detail::call_push<C>( c ),
382 2486 sjacqu01
                                   p );
383 2486 sjacqu01
    }
384 2486 sjacqu01
385 2486 sjacqu01
    template< class C >
386 2486 sjacqu01
    inline list_inserter< assign_detail::call_add_edge<C> >
387 2486 sjacqu01
    add_edge( C& c )
388 2486 sjacqu01
    {
389 2486 sjacqu01
        return make_list_inserter( assign_detail::call_add_edge<C>( c ) );
390 2486 sjacqu01
    }
391 2486 sjacqu01
392 2486 sjacqu01
} // namespace 'assign'
393 2486 sjacqu01
} // namespace 'boost'
394 2486 sjacqu01
395 2486 sjacqu01
#undef BOOST_ASSIGN_PARAMS1
396 2486 sjacqu01
#undef BOOST_ASSIGN_PARAMS2
397 2486 sjacqu01
#undef BOOST_ASSIGN_PARAMS3
398 2486 sjacqu01
#undef BOOST_ASSIGN_MAX_PARAMETERS
399 2486 sjacqu01
400 2486 sjacqu01
#endif