template_keyword.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright Daniel Wallin 2006.
  2. // Copyright Cromwell D. Enage 2017.
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_PARAMETER_TEMPLATE_KEYWORD_HPP
  7. #define BOOST_PARAMETER_TEMPLATE_KEYWORD_HPP
  8. #include <boost/parameter/aux_/template_keyword.hpp>
  9. #include <boost/parameter/config.hpp>
  10. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  11. #include <boost/mp11/integral.hpp>
  12. #include <boost/mp11/utility.hpp>
  13. #include <type_traits>
  14. #else
  15. #include <boost/mpl/bool.hpp>
  16. #include <boost/mpl/if.hpp>
  17. #include <boost/mpl/eval_if.hpp>
  18. #include <boost/mpl/identity.hpp>
  19. #include <boost/type_traits/add_lvalue_reference.hpp>
  20. #include <boost/type_traits/is_function.hpp>
  21. #include <boost/type_traits/is_array.hpp>
  22. #endif
  23. namespace boost { namespace parameter {
  24. template <typename Tag, typename T>
  25. struct template_keyword : ::boost::parameter::aux::template_keyword_base
  26. {
  27. typedef Tag key_type;
  28. typedef T value_type;
  29. // reference is needed for two reasons:
  30. //
  31. // 1. It is used in the body of arg_list<...>
  32. //
  33. // 2. It is the result of binding<...>, which we mistakenly told
  34. // people to use instead of value_type<...> to access named
  35. // template parameters
  36. //
  37. // It used to be that reference == value_type, but that broke when
  38. // the argument was a function or array type, because various
  39. // arg_list functions return reference.
  40. //
  41. // Simply making reference == value_type& would break all the
  42. // legacy code that uses binding<...> to access named template
  43. // parameters. -- David Abrahams
  44. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  45. using reference = typename ::boost::mp11::mp_eval_if<
  46. ::boost::mp11::mp_if<
  47. ::std::is_function<value_type>
  48. , ::boost::mp11::mp_true
  49. , ::std::is_array<value_type>
  50. >
  51. , ::std::add_lvalue_reference<value_type>
  52. , ::boost::mp11::mp_identity
  53. , value_type
  54. >::type;
  55. #else
  56. typedef typename ::boost::mpl::eval_if<
  57. typename ::boost::mpl::if_<
  58. ::boost::is_function<value_type>
  59. , ::boost::mpl::true_
  60. , ::boost::is_array<value_type>
  61. >::type
  62. , ::boost::add_lvalue_reference<value_type>
  63. , ::boost::mpl::identity<value_type>
  64. >::type reference;
  65. #endif // BOOST_PARAMETER_CAN_USE_MP11
  66. };
  67. }} // namespace boost::parameter
  68. #define BOOST_PARAMETER_TEMPLATE_KEYWORD(name) \
  69. namespace tag \
  70. { \
  71. struct name; \
  72. } \
  73. template <typename T> \
  74. struct name : ::boost::parameter::template_keyword<tag::name,T> \
  75. { \
  76. };
  77. /**/
  78. #endif // include guard