1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
3 Copyright (c) 2005 Eric Niebler
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
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>
37 namespace boost { namespace fusion
40 struct forward_traversal_tag;
41 struct fusion_sequence_tag;
43 template <typename Car, typename Cdr /*= nil_*/>
44 struct cons : sequence_base<cons<Car, Cdr> >
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;
54 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
58 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
59 explicit cons(typename detail::call_param<Car>::type in_car)
60 : car(in_car), cdr() {}
62 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
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) {}
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) {}
73 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
75 : car(rhs.car), cdr(rhs.cdr) {}
77 template <typename Sequence>
78 BOOST_FUSION_GPU_ENABLED
81 , typename boost::enable_if<
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
87 >::type = detail::enabler
89 : car(*fusion::begin(seq))
90 , cdr(fusion::next(fusion::begin(seq)), mpl::true_()) {}
92 template <typename Iterator>
93 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
94 cons(Iterator const& iter, mpl::true_ /*this_is_an_iterator*/)
96 , cdr(fusion::next(iter), mpl::true_()) {}
98 template <typename Car2, typename Cdr2>
99 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
100 cons& operator=(cons<Car2, Cdr2> const& rhs)
107 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
108 cons& operator=(cons const& rhs)
115 template <typename Sequence>
116 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
117 typename boost::enable_if<
119 traits::is_sequence<Sequence>
120 , mpl::not_<is_convertible<Sequence, Car> > >
122 operator=(Sequence const& seq)
124 typedef typename result_of::begin<Sequence const>::type Iterator;
125 Iterator iter = fusion::begin(seq);
126 this->assign_from_iter(iter);
130 template <typename Iterator>
131 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
132 void assign_from_iter(Iterator const& iter)
135 cdr.assign_from_iter(fusion::next(iter));