| 1 | /*============================================================================= |
|---|
| 2 | Copyright (c) 2003 Joel de Guzman |
|---|
| 3 | Copyright (c) 2004 Peder Holt |
|---|
| 4 | Copyright (c) 2005 Eric Niebler |
|---|
| 5 | |
|---|
| 6 | Use, modification and distribution is subject to the Boost Software |
|---|
| 7 | License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
|---|
| 8 | http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 9 | ==============================================================================*/ |
|---|
| 10 | #if !defined(FUSION_SEQUENCE_CONS_HPP) |
|---|
| 11 | #define FUSION_SEQUENCE_CONS_HPP |
|---|
| 12 | |
|---|
| 13 | #include <boost/call_traits.hpp> |
|---|
| 14 | #include <boost/spirit/fusion/detail/access.hpp> |
|---|
| 15 | #include <boost/spirit/fusion/sequence/begin.hpp> |
|---|
| 16 | #include <boost/spirit/fusion/sequence/end.hpp> |
|---|
| 17 | #include <boost/spirit/fusion/iterator/cons_iterator.hpp> |
|---|
| 18 | #include <boost/spirit/fusion/sequence/detail/cons_begin_end_traits.hpp> |
|---|
| 19 | #include <boost/spirit/fusion/sequence/as_fusion_sequence.hpp> |
|---|
| 20 | |
|---|
| 21 | namespace boost { namespace fusion |
|---|
| 22 | { |
|---|
| 23 | struct void_t; |
|---|
| 24 | |
|---|
| 25 | struct cons_tag; |
|---|
| 26 | |
|---|
| 27 | struct nil : sequence_base<nil> |
|---|
| 28 | { |
|---|
| 29 | typedef cons_tag tag; |
|---|
| 30 | typedef void_t car_type; |
|---|
| 31 | typedef void_t cdr_type; |
|---|
| 32 | }; |
|---|
| 33 | |
|---|
| 34 | template <typename Car, typename Cdr = nil> |
|---|
| 35 | struct cons : sequence_base<cons<Car,Cdr> > |
|---|
| 36 | { |
|---|
| 37 | typedef cons_tag tag; |
|---|
| 38 | typedef typename call_traits<Car>::value_type car_type; |
|---|
| 39 | typedef Cdr cdr_type; |
|---|
| 40 | |
|---|
| 41 | cons() |
|---|
| 42 | : car(), cdr() {} |
|---|
| 43 | |
|---|
| 44 | explicit cons( |
|---|
| 45 | typename call_traits<Car>::param_type car_ |
|---|
| 46 | , typename call_traits<Cdr>::param_type cdr_ = Cdr()) |
|---|
| 47 | : car(car_), cdr(cdr_) {} |
|---|
| 48 | |
|---|
| 49 | car_type car; |
|---|
| 50 | cdr_type cdr; |
|---|
| 51 | }; |
|---|
| 52 | |
|---|
| 53 | template <typename Car> |
|---|
| 54 | inline cons<Car> |
|---|
| 55 | make_cons(Car const& car) |
|---|
| 56 | { |
|---|
| 57 | return cons<Car>(car); |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | template <typename Car, typename Cdr> |
|---|
| 61 | inline cons<Car, Cdr> |
|---|
| 62 | make_cons(Car const& car, Cdr const& cdr) |
|---|
| 63 | { |
|---|
| 64 | return cons<Car, Cdr>(car, cdr); |
|---|
| 65 | } |
|---|
| 66 | }} |
|---|
| 67 | |
|---|
| 68 | #endif |
|---|
| 69 | |
|---|