source: NonGTP/Boost/boost/spirit/fusion/sequence/tuple10.hpp @ 857

Revision 857, 8.1 KB checked in by igarcia, 18 years ago (diff)
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        T0 m0;
73
74    private:
75
76        template <typename Iterator>
77        static T0
78        construct(Iterator const& i, detail::disambiguate_as_iterator)
79        {
80            return *i;
81        }
82
83        template <typename Tuple>
84        static T0
85        construct(Tuple const& t, detail::disambiguate_as_tuple)
86        {
87            return t.m0;
88        }
89
90        template <typename X>
91        static T0
92        construct(X const& v, detail::disambiguate_as_data)
93        {
94            return v;
95        }
96    };
97
98    template <typename T0, typename T1>
99    struct tuple2;
100
101    template <typename T0, typename T1>
102    struct tuple_data2 : sequence_base<tuple2<T0, T1> >
103    {
104        typedef mpl::vector2<T0, T1> types;
105        typedef tuple_tag tag;
106        typedef mpl::int_<2> size;
107        typedef tuple_data2 identity_type;
108
109        tuple_data2()
110            : m0(T0())
111            , m1(T1())
112        {}
113
114        tuple_data2(
115            typename detail::call_param<T0>::type _0
116          , typename detail::call_param<T1>::type _1
117        )
118            : m0(_0)
119            , m1(_1)
120        {}
121
122        template <typename A0, typename A1>
123        tuple_data2(detail::disambiguate_as_iterator, A0& _0, A1& _1)
124            : m0(*_0)
125            , m1(*_1)
126        {}
127
128        T0 m0;
129        T1 m1;
130    };
131
132    template <typename T0, typename T1, typename T2>
133    struct tuple3;
134
135    template <typename T0, typename T1, typename T2>
136    struct tuple_data3 : sequence_base<tuple3<T0, T1, T2> >
137    {
138        typedef mpl::vector3<T0, T1, T2> types;
139        typedef tuple_tag tag;
140        typedef mpl::int_<3> size;
141        typedef tuple_data3 identity_type;
142
143        tuple_data3()
144            : m0(T0())
145            , m1(T1())
146            , m2(T2())
147        {}
148
149        tuple_data3(
150            typename detail::call_param<T0>::type _0
151          , typename detail::call_param<T1>::type _1
152          , typename detail::call_param<T2>::type _2
153        )
154            : m0(_0)
155            , m1(_1)
156            , m2(_2)
157        {}
158
159        template <typename A0, typename A1, typename A2>
160        tuple_data3(detail::disambiguate_as_iterator, A0& _0, A1& _1, A2& _2)
161            : m0(*_0)
162            , m1(*_1)
163            , m2(*_2)
164        {}
165       
166        T0 m0;
167        T1 m1;
168        T2 m2;
169    };
170
171    template <typename T0, typename T1>
172    struct tuple2 : tuple_data2<T0, T1>
173    {
174        tuple2()
175            : tuple_data2<T0, T1>()
176        {}
177
178        tuple2(
179            typename detail::call_param<T0>::type _0
180          , typename detail::call_param<T1>::type _1
181        )
182            : tuple_data2<T0, T1>(_0, _1)
183        {}
184
185        template <typename X>
186        explicit tuple2(X const& x)
187            : tuple_data2<T0, T1>(construct(x, addressof(x)))
188        {}
189
190        template <typename U0, typename U1>
191        tuple2& operator=(tuple2<U0, U1> const& t)
192        {
193            this->m0 = t.m0;
194            this->m1 = t.m1;
195            return *this;
196        }
197
198        template <typename First, typename Second>
199        tuple2& operator=(std::pair<First, Second> const& p)
200        {
201            this->m0 = p.first;
202            this->m1 = p.second;
203            return *this;
204        }
205
206    private:
207
208        template <typename Iterator>
209        static tuple_data2<T0, T1>
210        construct(Iterator const& i, void const*)
211        {
212            typedef typename meta::next<Iterator>::type i1_type;
213            i1_type i1(fusion::next(i));
214            return tuple_data2<T0, T1>(detail::disambiguate_as_iterator(), i, i1);
215        }
216
217        template <typename Tuple>
218        static tuple_data2<T0, T1>
219        construct(Tuple const& t, sequence_root const*)
220        {
221            return tuple_data2<T0, T1>(t.m0, t.m1);
222        }
223
224        template <typename U0, typename U1>
225        static tuple_data2<T0, T1>
226        construct(std::pair<U0, U1> const& p, std::pair<U0, U1> const*)
227        {
228            return tuple_data2<T0, T1>(p.first, p.second);
229        }
230    };
231
232#if BOOST_WORKAROUND(__BORLANDC__, <= 0x551)
233    namespace detail
234    {
235        template <typename Iterator>
236        struct next_iter3
237        {
238            typedef typename meta::next<Iterator>::type i1_type;
239            typedef typename meta::next<i1_type>::type i2_type;
240        };
241    }
242#endif
243
244    template <typename T0, typename T1, typename T2>
245    struct tuple3 : tuple_data3<T0, T1, T2>
246    {
247        tuple3()
248            : tuple_data3<T0, T1, T2>()
249        {}
250
251        tuple3(
252            typename detail::call_param<T0>::type _0
253          , typename detail::call_param<T1>::type _1
254          , typename detail::call_param<T2>::type _2
255        )
256            : tuple_data3<T0, T1, T2>(_0, _1, _2)
257        {}
258
259        template <typename X>
260        explicit tuple3(X const& x)
261            : tuple_data3<T0, T1, T2>(construct(x, &x))
262        {}
263
264        template <typename U0, typename U1, typename U2>
265        tuple3& operator=(tuple3<U0, U1, U2> const& t)
266        {
267            this->m0 = t.m0;
268            this->m1 = t.m1;
269            this->m2 = t.m2;
270            return *this;
271        }
272
273    private:
274
275        template <typename Iterator>
276        static tuple_data3<T0, T1, T2>
277        construct(Iterator const& i, void const*)
278        {
279#if BOOST_WORKAROUND(__BORLANDC__, <= 0x551)
280            typedef detail::next_iter3<Iterator> next_iter;
281            next_iter::i1_type i1(fusion::next(i));
282            next_iter::i2_type i2(fusion::next(i1));
283#else
284            typedef typename meta::next<Iterator>::type i1_type;
285            typedef typename meta::next<i1_type>::type i2_type;
286            i1_type i1(fusion::next(i));
287            i2_type i2(fusion::next(i1));
288#endif
289            return tuple_data3<T0, T1, T2>(detail::disambiguate_as_iterator(), i, i1, i2);
290        }
291
292        template <typename Tuple>
293        static tuple_data3<T0, T1, T2>
294        construct(Tuple const& t, sequence_root const*)
295        {
296            return tuple_data3<T0, T1, T2>(t.m0, t.m1, t.m2);
297        }
298    };
299}}
300
301#endif
Note: See TracBrowser for help on using the repository browser.