]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*============================================================================= |
2 | Copyright (c) 2001-2011 Joel de Guzman | |
3 | Copyright (c) 2005 Eric Niebler | |
4 | ||
5 | Distributed under the Boost Software License, Version 1.0. (See accompanying | |
6 | file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
7 | ==============================================================================*/ | |
8 | #if !defined(FUSION_CONS_07172005_0843) | |
9 | #define FUSION_CONS_07172005_0843 | |
10 | ||
11 | #include <boost/fusion/support/config.hpp> | |
12 | #include <boost/fusion/support/void.hpp> | |
13 | #include <boost/fusion/support/detail/enabler.hpp> | |
14 | #include <boost/fusion/container/list/cons_fwd.hpp> | |
15 | #include <boost/fusion/support/detail/access.hpp> | |
16 | #include <boost/fusion/sequence/intrinsic/begin.hpp> | |
17 | #include <boost/fusion/sequence/intrinsic/end.hpp> | |
18 | #include <boost/fusion/iterator/next.hpp> | |
19 | #include <boost/fusion/iterator/deref.hpp> | |
20 | #include <boost/fusion/container/list/nil.hpp> | |
21 | #include <boost/fusion/container/list/cons_iterator.hpp> | |
22 | #include <boost/fusion/container/list/detail/begin_impl.hpp> | |
23 | #include <boost/fusion/container/list/detail/end_impl.hpp> | |
24 | #include <boost/fusion/container/list/detail/at_impl.hpp> | |
25 | #include <boost/fusion/container/list/detail/value_at_impl.hpp> | |
26 | #include <boost/fusion/container/list/detail/empty_impl.hpp> | |
27 | #include <boost/type_traits/is_convertible.hpp> | |
28 | #include <boost/type_traits/is_base_of.hpp> | |
29 | #include <boost/utility/enable_if.hpp> | |
30 | #include <boost/fusion/support/sequence_base.hpp> | |
31 | #include <boost/fusion/support/is_sequence.hpp> | |
32 | #include <boost/mpl/int.hpp> | |
33 | #include <boost/mpl/bool.hpp> | |
34 | #include <boost/mpl/and.hpp> | |
35 | #include <boost/mpl/not.hpp> | |
36 | ||
37 | namespace boost { namespace fusion | |
38 | { | |
39 | struct cons_tag; | |
40 | struct forward_traversal_tag; | |
41 | struct fusion_sequence_tag; | |
42 | ||
43 | template <typename Car, typename Cdr /*= nil_*/> | |
44 | struct cons : sequence_base<cons<Car, Cdr> > | |
45 | { | |
46 | typedef mpl::int_<Cdr::size::value+1> size; | |
47 | typedef cons_tag fusion_tag; | |
48 | typedef fusion_sequence_tag tag; // this gets picked up by MPL | |
49 | typedef mpl::false_ is_view; | |
50 | typedef forward_traversal_tag category; | |
51 | typedef Car car_type; | |
52 | typedef Cdr cdr_type; | |
53 | ||
54 | BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED | |
55 | cons() | |
56 | : car(), cdr() {} | |
57 | ||
58 | BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED | |
59 | explicit cons(typename detail::call_param<Car>::type in_car) | |
60 | : car(in_car), cdr() {} | |
61 | ||
62 | BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED | |
63 | cons( | |
64 | typename detail::call_param<Car>::type in_car | |
65 | , typename detail::call_param<Cdr>::type in_cdr) | |
66 | : car(in_car), cdr(in_cdr) {} | |
67 | ||
68 | template <typename Car2, typename Cdr2> | |
69 | BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED | |
70 | cons(cons<Car2, Cdr2> const& rhs) | |
71 | : car(rhs.car), cdr(rhs.cdr) {} | |
72 | ||
73 | BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED | |
74 | cons(cons const& rhs) | |
75 | : car(rhs.car), cdr(rhs.cdr) {} | |
76 | ||
77 | template <typename Sequence> | |
78 | BOOST_FUSION_GPU_ENABLED | |
79 | cons( | |
80 | Sequence const& seq | |
81 | , typename boost::enable_if< | |
82 | mpl::and_< | |
83 | traits::is_sequence<Sequence> | |
84 | , mpl::not_<is_base_of<cons, Sequence> > | |
85 | , mpl::not_<is_convertible<Sequence, Car> > > // use copy to car instead | |
86 | , detail::enabler_ | |
87 | >::type = detail::enabler | |
88 | ) | |
89 | : car(*fusion::begin(seq)) | |
90 | , cdr(fusion::next(fusion::begin(seq)), mpl::true_()) {} | |
91 | ||
92 | template <typename Iterator> | |
93 | BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED | |
94 | cons(Iterator const& iter, mpl::true_ /*this_is_an_iterator*/) | |
95 | : car(*iter) | |
96 | , cdr(fusion::next(iter), mpl::true_()) {} | |
97 | ||
98 | template <typename Car2, typename Cdr2> | |
99 | BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED | |
100 | cons& operator=(cons<Car2, Cdr2> const& rhs) | |
101 | { | |
102 | car = rhs.car; | |
103 | cdr = rhs.cdr; | |
104 | return *this; | |
105 | } | |
106 | ||
107 | BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED | |
108 | cons& operator=(cons const& rhs) | |
109 | { | |
110 | car = rhs.car; | |
111 | cdr = rhs.cdr; | |
112 | return *this; | |
113 | } | |
114 | ||
115 | template <typename Sequence> | |
116 | BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED | |
117 | typename boost::enable_if< | |
118 | mpl::and_< | |
119 | traits::is_sequence<Sequence> | |
120 | , mpl::not_<is_convertible<Sequence, Car> > > | |
121 | , cons&>::type | |
122 | operator=(Sequence const& seq) | |
123 | { | |
124 | typedef typename result_of::begin<Sequence const>::type Iterator; | |
125 | Iterator iter = fusion::begin(seq); | |
126 | this->assign_from_iter(iter); | |
127 | return *this; | |
128 | } | |
129 | ||
130 | template <typename Iterator> | |
131 | BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED | |
132 | void assign_from_iter(Iterator const& iter) | |
133 | { | |
134 | car = *iter; | |
135 | cdr.assign_from_iter(fusion::next(iter)); | |
136 | } | |
137 | ||
138 | car_type car; | |
139 | cdr_type cdr; | |
140 | }; | |
141 | }} | |
142 | ||
143 | #endif | |
144 |