1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
3 http://spirit.sourceforge.net/
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 #ifndef BOOST_SPIRIT_MAKE_CONS_OCTOBER_16_2008_1252PM
9 #define BOOST_SPIRIT_MAKE_CONS_OCTOBER_16_2008_1252PM
15 #include <boost/spirit/include/phoenix_limits.hpp> // needs to be included before proto
16 #include <boost/proto/proto.hpp>
17 #include <boost/mpl/eval_if.hpp>
18 #include <boost/fusion/include/cons.hpp>
19 #include <boost/type_traits/remove_const.hpp>
20 #include <boost/type_traits/is_abstract.hpp>
21 #include <boost/type_traits/is_function.hpp>
22 #include <boost/type_traits/add_reference.hpp>
23 #include <boost/utility/enable_if.hpp>
25 namespace boost { namespace spirit { namespace detail
28 struct as_meta_element
29 : mpl::eval_if_c<is_abstract<T>::value || is_function<T>::value
30 , add_reference<T>, remove_const<T> >
34 struct as_meta_element<T&> : as_meta_element<T> // always store by value
37 template <typename T, int N>
38 struct as_meta_element<T[N]>
40 typedef const T(&type)[N];
45 template <typename Car, typename Cdr = fusion::nil_>
48 typedef typename as_meta_element<Car>::type car_type; typedef typename fusion::cons<car_type, Cdr> type;
52 template <typename Car, typename Cdr>
53 fusion::cons<typename as_meta_element<Car>::type, Cdr>
54 make_cons(Car const& car, Cdr const& cdr)
56 typedef typename as_meta_element<Car>::type car_type;
57 typedef typename fusion::cons<car_type, Cdr> result;
58 return result(car, cdr);
61 template <typename Car>
62 fusion::cons<typename as_meta_element<Car>::type>
63 make_cons(Car const& car)
65 typedef typename as_meta_element<Car>::type car_type;
66 typedef typename fusion::cons<car_type> result;
70 #if defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 0)
71 // workaround for gcc-4.0 bug where illegal function types
72 // can be formed (const is added to function type)
73 // description: http://lists.boost.org/Archives/boost/2009/04/150743.php
74 template <typename Car>
75 fusion::cons<typename as_meta_element<Car>::type>
76 make_cons(Car& car, typename enable_if<is_function<Car> >::type* = 0)
78 typedef typename as_meta_element<Car>::type car_type;
79 typedef typename fusion::cons<car_type> result;