comparison DEPENDENCIES/generic/include/boost/fusion/container/list/cons.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
comparison
equal deleted inserted replaced
15:663ca0da4350 16:2665513ce2d3
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/container/list/cons_fwd.hpp>
12 #include <boost/fusion/support/detail/access.hpp>
13 #include <boost/fusion/sequence/intrinsic/begin.hpp>
14 #include <boost/fusion/sequence/intrinsic/end.hpp>
15 #include <boost/fusion/iterator/next.hpp>
16 #include <boost/fusion/iterator/deref.hpp>
17 #include <boost/fusion/container/list/cons_iterator.hpp>
18 #include <boost/fusion/container/list/detail/begin_impl.hpp>
19 #include <boost/fusion/container/list/detail/end_impl.hpp>
20 #include <boost/fusion/container/list/detail/at_impl.hpp>
21 #include <boost/fusion/container/list/detail/value_at_impl.hpp>
22 #include <boost/fusion/container/list/detail/empty_impl.hpp>
23 #include <boost/type_traits/is_convertible.hpp>
24 #include <boost/utility/enable_if.hpp>
25 #include <boost/fusion/support/sequence_base.hpp>
26 #include <boost/mpl/int.hpp>
27 #include <boost/mpl/bool.hpp>
28 #include <boost/mpl/or.hpp>
29
30 namespace boost { namespace fusion
31 {
32 struct void_;
33 struct cons_tag;
34 struct forward_traversal_tag;
35 struct fusion_sequence_tag;
36
37 struct nil_ : sequence_base<nil_>
38 {
39 typedef mpl::int_<0> size;
40 typedef cons_tag fusion_tag;
41 typedef fusion_sequence_tag tag; // this gets picked up by MPL
42 typedef mpl::false_ is_view;
43 typedef forward_traversal_tag category;
44 typedef void_ car_type;
45 typedef void_ cdr_type;
46
47 nil_() {}
48
49 template <typename Iterator>
50 nil_(Iterator const& /*iter*/, mpl::true_ /*this_is_an_iterator*/)
51 {}
52
53 template <typename Iterator>
54 void assign_from_iter(Iterator const& /*iter*/)
55 {
56 }
57 };
58
59 template <typename Car, typename Cdr /*= nil_*/>
60 struct cons : sequence_base<cons<Car, Cdr> >
61 {
62 typedef mpl::int_<Cdr::size::value+1> size;
63 typedef cons_tag fusion_tag;
64 typedef fusion_sequence_tag tag; // this gets picked up by MPL
65 typedef mpl::false_ is_view;
66 typedef forward_traversal_tag category;
67 typedef Car car_type;
68 typedef Cdr cdr_type;
69
70 cons()
71 : car(), cdr() {}
72
73 explicit cons(typename detail::call_param<Car>::type in_car)
74 : car(in_car), cdr() {}
75
76 cons(
77 typename detail::call_param<Car>::type in_car
78 , typename detail::call_param<Cdr>::type in_cdr)
79 : car(in_car), cdr(in_cdr) {}
80
81 template <typename Car2, typename Cdr2>
82 cons(cons<Car2, Cdr2> const& rhs)
83 : car(rhs.car), cdr(rhs.cdr) {}
84
85 cons(cons const& rhs)
86 : car(rhs.car), cdr(rhs.cdr) {}
87
88 template <typename Sequence>
89 cons(
90 Sequence const& seq
91 , typename boost::disable_if<
92 mpl::or_<
93 is_convertible<Sequence, cons> // use copy ctor instead
94 , is_convertible<Sequence, Car> // use copy to car instead
95 >
96 >::type* /*dummy*/ = 0
97 )
98 : car(*fusion::begin(seq))
99 , cdr(fusion::next(fusion::begin(seq)), mpl::true_()) {}
100
101 template <typename Iterator>
102 cons(Iterator const& iter, mpl::true_ /*this_is_an_iterator*/)
103 : car(*iter)
104 , cdr(fusion::next(iter), mpl::true_()) {}
105
106 template <typename Car2, typename Cdr2>
107 cons& operator=(cons<Car2, Cdr2> const& rhs)
108 {
109 car = rhs.car;
110 cdr = rhs.cdr;
111 return *this;
112 }
113
114 cons& operator=(cons const& rhs)
115 {
116 car = rhs.car;
117 cdr = rhs.cdr;
118 return *this;
119 }
120
121 template <typename Sequence>
122 typename boost::disable_if<is_convertible<Sequence, Car>, cons&>::type
123 operator=(Sequence const& seq)
124 {
125 typedef typename result_of::begin<Sequence const>::type Iterator;
126 Iterator iter = fusion::begin(seq);
127 this->assign_from_iter(iter);
128 return *this;
129 }
130
131 template <typename Iterator>
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