Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/boost/spirit/fusion/sequence/tuple10.hpp @ 29

Last change on this file since 29 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 7.9 KB
Line 
1/*=============================================================================
2    Copyright (c) 2001-2003 Joel de Guzman
3
4    Use, modification and distribution is subject to the Boost Software
5    License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6    http://www.boost.org/LICENSE_1_0.txt)
7==============================================================================*/
8#if !defined(FUSION_SEQUENCE_TUPLE10_HPP)
9#define FUSION_SEQUENCE_TUPLE10_HPP
10
11#include <boost/spirit/fusion/detail/config.hpp>
12#include <boost/spirit/fusion/sequence/detail/tuple10.hpp>
13#include <boost/spirit/fusion/sequence/detail/sequence_base.hpp>
14#include <boost/spirit/fusion/detail/access.hpp>
15#include <utility> // for std::pair
16#include <boost/mpl/int.hpp>
17#include <boost/mpl/vector/vector10.hpp>
18#include <boost/mpl/if.hpp>
19#include <boost/utility/addressof.hpp>
20
21namespace boost { namespace fusion
22{
23    namespace meta
24    {
25        template <typename Iterator>
26        struct next;
27    }
28
29    struct tuple_tag;
30
31    struct tuple0 : sequence_base<tuple0>
32    {
33        typedef mpl::void_ types;
34        typedef tuple_tag tag;
35        typedef mpl::int_<0> size;
36        typedef tuple0 identity_type;
37
38        tuple0() {}
39
40        template <typename Iterator>
41        tuple0(Iterator const& i) {}
42    };
43
44    template <typename T0>
45    struct tuple1 : sequence_base<tuple1<T0> >
46    {
47        typedef mpl::vector1<T0> types;
48        typedef tuple_tag tag;
49        typedef mpl::int_<1> size;
50        typedef tuple1 identity_type;
51
52        tuple1()
53            : m0(T0())
54        {}
55
56        template <typename X>
57        explicit tuple1(X const& x)
58            : m0(construct(x, detail::disambiguate<X, T0>::call()))
59        {}
60
61        tuple1(typename detail::call_param<T0>::type _0)
62            : m0(_0)
63        {}
64
65        template <typename U0>
66        tuple1& operator=(tuple1<U0> const& t)
67        {
68            m0 = t.m0;
69            return *this;
70        }
71
72        tuple1& operator=(tuple1 const& t)
73        {
74            m0 = t.m0;
75            return *this;
76        }
77
78        T0 m0;
79
80    private:
81
82        template <typename Iterator>
83        static T0
84        construct(Iterator const& i, detail::disambiguate_as_iterator)
85        {
86            return *i;
87        }
88
89        template <typename Tuple>
90        static T0
91        construct(Tuple const& t, detail::disambiguate_as_tuple)
92        {
93            return t.m0;
94        }
95
96        template <typename X>
97        static T0
98        construct(X const& v, detail::disambiguate_as_data)
99        {
100            return v;
101        }
102    };
103
104    template <typename T0, typename T1>
105    struct tuple2;
106
107    template <typename T0, typename T1>
108    struct tuple_data2 : sequence_base<tuple2<T0, T1> >
109    {
110        typedef mpl::vector2<T0, T1> types;
111        typedef tuple_tag tag;
112        typedef mpl::int_<2> size;
113        typedef tuple_data2 identity_type;
114
115        tuple_data2()
116            : m0(T0())
117            , m1(T1())
118        {}
119
120        tuple_data2(
121            typename detail::call_param<T0>::type _0
122          , typename detail::call_param<T1>::type _1
123        )
124            : m0(_0)
125            , m1(_1)
126        {}
127
128        template <typename A0, typename A1>
129        tuple_data2(detail::disambiguate_as_iterator, A0& _0, A1& _1)
130            : m0(*_0)
131            , m1(*_1)
132        {}
133
134        T0 m0;
135        T1 m1;
136    };
137
138    template <typename T0, typename T1, typename T2>
139    struct tuple3;
140
141    template <typename T0, typename T1, typename T2>
142    struct tuple_data3 : sequence_base<tuple3<T0, T1, T2> >
143    {
144        typedef mpl::vector3<T0, T1, T2> types;
145        typedef tuple_tag tag;
146        typedef mpl::int_<3> size;
147        typedef tuple_data3 identity_type;
148
149        tuple_data3()
150            : m0(T0())
151            , m1(T1())
152            , m2(T2())
153        {}
154
155        tuple_data3(
156            typename detail::call_param<T0>::type _0
157          , typename detail::call_param<T1>::type _1
158          , typename detail::call_param<T2>::type _2
159        )
160            : m0(_0)
161            , m1(_1)
162            , m2(_2)
163        {}
164
165        template <typename A0, typename A1, typename A2>
166        tuple_data3(detail::disambiguate_as_iterator, A0& _0, A1& _1, A2& _2)
167            : m0(*_0)
168            , m1(*_1)
169            , m2(*_2)
170        {}
171       
172        T0 m0;
173        T1 m1;
174        T2 m2;
175    };
176
177    template <typename T0, typename T1>
178    struct tuple2 : tuple_data2<T0, T1>
179    {
180        tuple2()
181            : tuple_data2<T0, T1>()
182        {}
183
184        tuple2(
185            typename detail::call_param<T0>::type _0
186          , typename detail::call_param<T1>::type _1
187        )
188            : tuple_data2<T0, T1>(_0, _1)
189        {}
190
191        template <typename X>
192        explicit tuple2(X const& x)
193            : tuple_data2<T0, T1>(construct(x, addressof(x)))
194        {}
195
196        template <typename U0, typename U1>
197        tuple2& operator=(tuple2<U0, U1> const& t)
198        {
199            this->m0 = t.m0;
200            this->m1 = t.m1;
201            return *this;
202        }
203
204        template <typename First, typename Second>
205        tuple2& operator=(std::pair<First, Second> const& p)
206        {
207            this->m0 = p.first;
208            this->m1 = p.second;
209            return *this;
210        }
211
212    private:
213
214        template <typename Iterator>
215        static tuple_data2<T0, T1>
216        construct(Iterator const& i, void const*)
217        {
218            typedef typename meta::next<Iterator>::type i1_type;
219            i1_type i1(fusion::next(i));
220            return tuple_data2<T0, T1>(detail::disambiguate_as_iterator(), i, i1);
221        }
222
223        template <typename Tuple>
224        static tuple_data2<T0, T1>
225        construct(Tuple const& t, sequence_root const*)
226        {
227            return tuple_data2<T0, T1>(t.m0, t.m1);
228        }
229
230        template <typename U0, typename U1>
231        static tuple_data2<T0, T1>
232        construct(std::pair<U0, U1> const& p, std::pair<U0, U1> const*)
233        {
234            return tuple_data2<T0, T1>(p.first, p.second);
235        }
236    };
237
238#if BOOST_WORKAROUND(__BORLANDC__, <= 0x551)
239    namespace detail
240    {
241        template <typename Iterator>
242        struct next_iter3
243        {
244            typedef typename meta::next<Iterator>::type i1_type;
245            typedef typename meta::next<i1_type>::type i2_type;
246        };
247    }
248#endif
249
250    template <typename T0, typename T1, typename T2>
251    struct tuple3 : tuple_data3<T0, T1, T2>
252    {
253        tuple3()
254            : tuple_data3<T0, T1, T2>()
255        {}
256
257        tuple3(
258            typename detail::call_param<T0>::type _0
259          , typename detail::call_param<T1>::type _1
260          , typename detail::call_param<T2>::type _2
261        )
262            : tuple_data3<T0, T1, T2>(_0, _1, _2)
263        {}
264
265        template <typename X>
266        explicit tuple3(X const& x)
267            : tuple_data3<T0, T1, T2>(construct(x, &x))
268        {}
269
270        template <typename U0, typename U1, typename U2>
271        tuple3& operator=(tuple3<U0, U1, U2> const& t)
272        {
273            this->m0 = t.m0;
274            this->m1 = t.m1;
275            this->m2 = t.m2;
276            return *this;
277        }
278
279    private:
280
281        template <typename Iterator>
282        static tuple_data3<T0, T1, T2>
283        construct(Iterator const& i, void const*)
284        {
285#if BOOST_WORKAROUND(__BORLANDC__, <= 0x551)
286            typedef detail::next_iter3<Iterator> next_iter;
287            next_iter::i1_type i1(fusion::next(i));
288            next_iter::i2_type i2(fusion::next(i1));
289#else
290            typedef typename meta::next<Iterator>::type i1_type;
291            typedef typename meta::next<i1_type>::type i2_type;
292            i1_type i1(fusion::next(i));
293            i2_type i2(fusion::next(i1));
294#endif
295            return tuple_data3<T0, T1, T2>(detail::disambiguate_as_iterator(), i, i1, i2);
296        }
297
298        template <typename Tuple>
299        static tuple_data3<T0, T1, T2>
300        construct(Tuple const& t, sequence_root const*)
301        {
302            return tuple_data3<T0, T1, T2>(t.m0, t.m1, t.m2);
303        }
304    };
305}}
306
307#endif
Note: See TracBrowser for help on using the repository browser.