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/mpl/eval_if.hpp> 16 #include <boost/fusion/include/cons.hpp> 17 #include <boost/type_traits/remove_const.hpp> 18 #include <boost/type_traits/is_abstract.hpp> 19 #include <boost/type_traits/is_function.hpp> 20 #include <boost/type_traits/add_reference.hpp> 21 #include <boost/utility/enable_if.hpp> 22 23 namespace boost { namespace spirit { namespace detail 24 { 25 template <typename T> 26 struct as_meta_element 27 : mpl::eval_if_c<is_abstract<T>::value || is_function<T>::value 28 , add_reference<T>, remove_const<T> > 29 {}; 30 31 template <typename T> 32 struct as_meta_element<T&> : as_meta_element<T> // always store by value 33 {}; 34 35 template <typename T, int N> 36 struct as_meta_element<T[N]> 37 { 38 typedef const T(&type)[N]; 39 }; 40 41 namespace result_of 42 { 43 template <typename Car, typename Cdr = fusion::nil_> 44 struct make_cons 45 { 46 typedef typename as_meta_element<Car>::type car_type; typedef typename fusion::cons<car_type, Cdr> type; 47 }; 48 } 49 50 template <typename Car, typename Cdr> 51 fusion::cons<typename as_meta_element<Car>::type, Cdr> make_cons(Car const & car,Cdr const & cdr)52 make_cons(Car const& car, Cdr const& cdr) 53 { 54 typedef typename as_meta_element<Car>::type car_type; 55 typedef typename fusion::cons<car_type, Cdr> result; 56 return result(car, cdr); 57 } 58 59 template <typename Car> 60 fusion::cons<typename as_meta_element<Car>::type> make_cons(Car const & car)61 make_cons(Car const& car) 62 { 63 typedef typename as_meta_element<Car>::type car_type; 64 typedef typename fusion::cons<car_type> result; 65 return result(car); 66 } 67 68 #if defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 0) 69 // workaround for gcc-4.0 bug where illegal function types 70 // can be formed (const is added to function type) 71 // description: http://lists.boost.org/Archives/boost/2009/04/150743.php 72 template <typename Car> 73 fusion::cons<typename as_meta_element<Car>::type> make_cons(Car & car,typename enable_if<is_function<Car>>::type * =0)74 make_cons(Car& car, typename enable_if<is_function<Car> >::type* = 0) 75 { 76 typedef typename as_meta_element<Car>::type car_type; 77 typedef typename fusion::cons<car_type> result; 78 return result(car); 79 } 80 #endif 81 }}} 82 83 #endif 84