~ubuntu-branches/ubuntu/breezy/aqsis/breezy

« back to all changes in this revision

Viewing changes to boost/boost/mpl/for_each.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Will Newton
  • Date: 2004-12-07 20:06:49 UTC
  • Revision ID: james.westby@ubuntu.com-20041207200649-fccswkrvp4oc8lmn
Tags: upstream-0.9.3
ImportĀ upstreamĀ versionĀ 0.9.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//-----------------------------------------------------------------------------
 
2
// boost mpl/for_each.hpp header file
 
3
// See http://www.boost.org for updates, documentation, and revision history.
 
4
//-----------------------------------------------------------------------------
 
5
//
 
6
// Copyright (c) 2000-02
 
7
// Aleksey Gurtovoy
 
8
//
 
9
// Permission to use, copy, modify, distribute and sell this software
 
10
// and its documentation for any purpose is hereby granted without fee, 
 
11
// provided that the above copyright notice appears in all copies and 
 
12
// that both the copyright notice and this permission notice appear in 
 
13
// supporting documentation. No representations are made about the 
 
14
// suitability of this software for any purpose. It is provided "as is" 
 
15
// without express or implied warranty.
 
16
 
 
17
#ifndef BOOST_MPL_FOR_EACH_HPP_INCLUDED
 
18
#define BOOST_MPL_FOR_EACH_HPP_INCLUDED
 
19
 
 
20
#include "boost/mpl/begin_end.hpp"
 
21
#include "boost/mpl/apply.hpp"
 
22
#include "boost/mpl/bool.hpp"
 
23
#include "boost/mpl/lambda.hpp"
 
24
#include "boost/mpl/identity.hpp"
 
25
#include "boost/mpl/aux_/unwrap.hpp"
 
26
 
 
27
#include "boost/type_traits/is_same.hpp"
 
28
#include "boost/utility/value_init.hpp"
 
29
 
 
30
namespace boost {
 
31
namespace mpl {
 
32
 
 
33
namespace aux {
 
34
 
 
35
template <bool done = true>
 
36
struct for_each_impl
 
37
{
 
38
    template<
 
39
          typename Iterator
 
40
        , typename LastIterator
 
41
        , typename TransformFunc
 
42
        , typename F
 
43
        >
 
44
    static void execute(
 
45
          Iterator*
 
46
        , LastIterator*
 
47
        , TransformFunc*
 
48
        , F
 
49
        )
 
50
    {
 
51
    }
 
52
};
 
53
 
 
54
template <>
 
55
struct for_each_impl<false>
 
56
{
 
57
    template<
 
58
          typename Iterator
 
59
        , typename LastIterator
 
60
        , typename TransformFunc
 
61
        , typename F
 
62
        >
 
63
    static void execute(
 
64
          Iterator*
 
65
        , LastIterator*
 
66
        , TransformFunc* 
 
67
        , F f
 
68
        )
 
69
    {
 
70
        typedef typename Iterator::type item;
 
71
        typedef typename apply1<TransformFunc,item>::type arg;
 
72
    
 
73
        // dwa 2002/9/10 -- make sure not to invoke undefined behavior
 
74
        // when we pass arg.
 
75
        value_initialized<arg> x;
 
76
        aux::unwrap(f, 0)(boost::get(x));
 
77
        
 
78
        typedef typename Iterator::next iter;
 
79
        for_each_impl<boost::is_same<iter,LastIterator>::value>::execute(
 
80
            (iter*)0, (LastIterator*)0, (TransformFunc*)0, f);
 
81
    }
 
82
};
 
83
 
 
84
} // namespace aux
 
85
 
 
86
// agurt, 17/mar/02: pointer default parameters are necessary to workaround 
 
87
// MSVC 6.5 function template signature's mangling bug
 
88
template<
 
89
      typename Sequence
 
90
    , typename TransformOp
 
91
    , typename F
 
92
    >
 
93
inline
 
94
void for_each(F f, Sequence* = 0, TransformOp* = 0)
 
95
{
 
96
    typedef typename begin<Sequence>::type first;
 
97
    typedef typename end<Sequence>::type last;
 
98
    typedef typename lambda<TransformOp>::type transform_op;
 
99
 
 
100
    aux::for_each_impl< boost::is_same<first,last>::value >::execute(
 
101
        (first*)0, (last*)0, (transform_op*)0, f);
 
102
}
 
103
 
 
104
template<
 
105
      typename Sequence
 
106
    , typename F
 
107
    >
 
108
inline
 
109
void for_each(F f, Sequence* = 0)
 
110
{
 
111
    for_each<Sequence, identity<> >(f);
 
112
}
 
113
 
 
114
} // namespace mpl
 
115
} // namespace boost
 
116
 
 
117
#endif // BOOST_MPL_FOR_EACH_HPP_INCLUDED