/src/contrib/boost/spirit/home/support/detail/make_cons.hpp

http://pythonocc.googlecode.com/ · C++ Header · 85 lines · 65 code · 10 blank · 10 comment · 5 complexity · 11e2a36740b7d49df002b36439721cf8 MD5 · raw file

  1. /*=============================================================================
  2. Copyright (c) 2001-2010 Joel de Guzman
  3. http://spirit.sourceforge.net/
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. =============================================================================*/
  7. #ifndef BOOST_SPIRIT_MAKE_CONS_OCTOBER_16_2008_1252PM
  8. #define BOOST_SPIRIT_MAKE_CONS_OCTOBER_16_2008_1252PM
  9. #if defined(_MSC_VER)
  10. #pragma once
  11. #endif
  12. #include <boost/proto/proto.hpp>
  13. #include <boost/mpl/eval_if.hpp>
  14. #include <boost/fusion/include/cons.hpp>
  15. #include <boost/type_traits/remove_const.hpp>
  16. #include <boost/type_traits/is_abstract.hpp>
  17. #include <boost/type_traits/is_function.hpp>
  18. #include <boost/type_traits/add_reference.hpp>
  19. #include <boost/utility/enable_if.hpp>
  20. namespace boost { namespace spirit { namespace detail
  21. {
  22. template <typename T>
  23. struct as_meta_element
  24. : mpl::eval_if_c<is_abstract<T>::value || is_function<T>::value
  25. , add_reference<T>, remove_const<T> >
  26. {};
  27. template <typename T>
  28. struct as_meta_element<T&> : as_meta_element<T> // always store by value
  29. {};
  30. template <typename T, int N>
  31. struct as_meta_element<T[N]>
  32. {
  33. typedef const T(&type)[N];
  34. };
  35. namespace result_of
  36. {
  37. template <typename Car, typename Cdr = fusion::nil>
  38. struct make_cons
  39. {
  40. typedef typename as_meta_element<Car>::type car_type;
  41. typedef typename fusion::cons<car_type, Cdr> type;
  42. };
  43. }
  44. template <typename Car, typename Cdr>
  45. fusion::cons<typename as_meta_element<Car>::type, Cdr>
  46. make_cons(Car const& car, Cdr const& cdr)
  47. {
  48. typedef typename as_meta_element<Car>::type car_type;
  49. typedef typename fusion::cons<car_type, Cdr> result;
  50. return result(car, cdr);
  51. }
  52. template <typename Car>
  53. fusion::cons<typename as_meta_element<Car>::type>
  54. make_cons(Car const& car)
  55. {
  56. typedef typename as_meta_element<Car>::type car_type;
  57. typedef typename fusion::cons<car_type> result;
  58. return result(car);
  59. }
  60. #if defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 0)
  61. // workaround for gcc-4.0 bug where illegal function types
  62. // can be formed (const is added to function type)
  63. // description: http://lists.boost.org/Archives/boost/2009/04/150743.php
  64. template <typename Car>
  65. fusion::cons<typename as_meta_element<Car>::type>
  66. make_cons(Car& car, typename enable_if<is_function<Car> >::type* = 0)
  67. {
  68. typedef typename as_meta_element<Car>::type car_type;
  69. typedef typename fusion::cons<car_type> result;
  70. return result(car);
  71. }
  72. #endif
  73. }}}
  74. #endif