1 /*============================================================================= 2 Copyright (c) 2001-2011 Joel de Guzman 3 http://spirit.sourceforge.net/ 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 #ifndef BOOST_SPIRIT_MAKE_CONS_OCTOBER_16_2008_1252PM 9 #define BOOST_SPIRIT_MAKE_CONS_OCTOBER_16_2008_1252PM 10 11 #if defined(_MSC_VER) 12 #pragma once 13 #endif 14 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> 24 25 namespace boost { namespace spirit { namespace detail 26 { 27 template <typename T> 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> > 31 {}; 32 33 template <typename T> 34 struct as_meta_element<T&> : as_meta_element<T> // always store by value 35 {}; 36 37 template <typename T, int N> 38 struct as_meta_element<T[N]> 39 { 40 typedef const T(&type)[N]; 41 }; 42 43 namespace result_of 44 { 45 template <typename Car, typename Cdr = fusion::nil_> 46 struct make_cons 47 { 48 typedef typename as_meta_element<Car>::type car_type; typedef typename fusion::cons<car_type, Cdr> type; 49 }; 50 } 51 52 template <typename Car, typename Cdr> 53 fusion::cons<typename as_meta_element<Car>::type, Cdr> make_cons(Car const & car,Cdr const & cdr)54 make_cons(Car const& car, Cdr const& cdr) 55 { 56 typedef typename as_meta_element<Car>::type car_type; 57 typedef typename fusion::cons<car_type, Cdr> result; 58 return result(car, cdr); 59 } 60 61 template <typename Car> 62 fusion::cons<typename as_meta_element<Car>::type> make_cons(Car const & car)63 make_cons(Car const& car) 64 { 65 typedef typename as_meta_element<Car>::type car_type; 66 typedef typename fusion::cons<car_type> result; 67 return result(car); 68 } 69 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> make_cons(Car & car,typename enable_if<is_function<Car>>::type * =0)76 make_cons(Car& car, typename enable_if<is_function<Car> >::type* = 0) 77 { 78 typedef typename as_meta_element<Car>::type car_type; 79 typedef typename fusion::cons<car_type> result; 80 return result(car); 81 } 82 #endif 83 }}} 84 85 #endif 86