epoc32/include/stdapis/boost/mpl/for_each.hpp
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 3 e1b950c65cb4
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
     1 
     2 #ifndef BOOST_MPL_FOR_EACH_HPP_INCLUDED
     3 #define BOOST_MPL_FOR_EACH_HPP_INCLUDED
     4 
     5 // Copyright Aleksey Gurtovoy 2000-2004
     6 //
     7 // Distributed under the Boost Software License, Version 1.0. 
     8 // (See accompanying file LICENSE_1_0.txt or copy at 
     9 // http://www.boost.org/LICENSE_1_0.txt)
    10 //
    11 // See http://www.boost.org/libs/mpl for documentation.
    12 
    13 // $Source: /cvsroot/boost/boost/boost/mpl/for_each.hpp,v $
    14 // $Date: 2004/09/04 01:33:46 $
    15 // $Revision: 1.9 $
    16 
    17 #include <boost/mpl/begin_end.hpp>
    18 #include <boost/mpl/apply.hpp>
    19 #include <boost/mpl/bool.hpp>
    20 #include <boost/mpl/next_prior.hpp>
    21 #include <boost/mpl/deref.hpp>
    22 #include <boost/mpl/identity.hpp>
    23 #include <boost/mpl/aux_/unwrap.hpp>
    24 
    25 #include <boost/type_traits/is_same.hpp>
    26 #include <boost/utility/value_init.hpp>
    27 
    28 namespace boost { namespace mpl {
    29 
    30 namespace aux {
    31 
    32 template< bool done = true >
    33 struct for_each_impl
    34 {
    35     template<
    36           typename Iterator
    37         , typename LastIterator
    38         , typename TransformFunc
    39         , typename F
    40         >
    41     static void execute(
    42           Iterator*
    43         , LastIterator*
    44         , TransformFunc*
    45         , F
    46         )
    47     {
    48     }
    49 };
    50 
    51 template<>
    52 struct for_each_impl<false>
    53 {
    54     template<
    55           typename Iterator
    56         , typename LastIterator
    57         , typename TransformFunc
    58         , typename F
    59         >
    60     static void execute(
    61           Iterator*
    62         , LastIterator*
    63         , TransformFunc* 
    64         , F f
    65         )
    66     {
    67         typedef typename deref<Iterator>::type item;
    68         typedef typename apply1<TransformFunc,item>::type arg;
    69     
    70         // dwa 2002/9/10 -- make sure not to invoke undefined behavior
    71         // when we pass arg.
    72         value_initialized<arg> x;
    73         aux::unwrap(f, 0)(boost::get(x));
    74         
    75         typedef typename mpl::next<Iterator>::type iter;
    76         for_each_impl<boost::is_same<iter,LastIterator>::value>
    77             ::execute((iter*)0, (LastIterator*)0, (TransformFunc*)0, f);
    78     }
    79 };
    80 
    81 } // namespace aux
    82 
    83 // agurt, 17/mar/02: pointer default parameters are necessary to workaround 
    84 // MSVC 6.5 function template signature's mangling bug
    85 template<
    86       typename Sequence
    87     , typename TransformOp
    88     , typename F
    89     >
    90 inline
    91 void for_each(F f, Sequence* = 0, TransformOp* = 0)
    92 {
    93     typedef typename begin<Sequence>::type first;
    94     typedef typename end<Sequence>::type last;
    95 
    96     aux::for_each_impl< boost::is_same<first,last>::value >
    97         ::execute((first*)0, (last*)0, (TransformOp*)0, f);
    98 }
    99 
   100 template<
   101       typename Sequence
   102     , typename F
   103     >
   104 inline
   105 void for_each(F f, Sequence* = 0)
   106 {
   107     for_each<Sequence, identity<> >(f);
   108 }
   109 
   110 }}
   111 
   112 #endif // BOOST_MPL_FOR_EACH_HPP_INCLUDED