function_type_tpl_param.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // Copyright Frank Mori Hess 2009.
  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. #include <boost/parameter/template_keyword.hpp>
  7. #include <boost/parameter/parameters.hpp>
  8. #include <boost/parameter/required.hpp>
  9. #include <boost/parameter/value_type.hpp>
  10. #include <boost/parameter/config.hpp>
  11. #if defined(BOOST_PARAMETER_CAN_USE_MP11) && \
  12. BOOST_WORKAROUND(BOOST_MSVC, < 1920)
  13. #include <type_traits>
  14. #else
  15. #include <boost/mpl/bool.hpp>
  16. #include <boost/mpl/if.hpp>
  17. #include <boost/type_traits/is_same.hpp>
  18. #endif
  19. namespace test {
  20. namespace keywords {
  21. BOOST_PARAMETER_TEMPLATE_KEYWORD(function_type)
  22. } // namespace keywords
  23. template <typename K, typename A>
  24. #if BOOST_WORKAROUND(BOOST_MSVC, < 1920)
  25. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  26. using X = boost::parameter::value_type<
  27. #else
  28. struct X
  29. : boost::parameter::value_type<
  30. #endif
  31. typename boost::parameter::parameters<
  32. boost::parameter::required<K>
  33. >::BOOST_NESTED_TEMPLATE bind<A>::type
  34. , K
  35. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  36. >;
  37. #else
  38. >
  39. {
  40. };
  41. #endif
  42. #else // MSVC-14.2
  43. struct X
  44. {
  45. typedef typename boost::parameter::value_type<
  46. typename boost::parameter::parameters<
  47. boost::parameter::required<K>
  48. >::BOOST_NESTED_TEMPLATE bind<A>::type
  49. , K
  50. >::type type;
  51. };
  52. #endif
  53. template <typename T>
  54. #if BOOST_WORKAROUND(BOOST_MSVC, < 1920)
  55. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  56. using Y = std::is_same<
  57. #else
  58. struct Y
  59. : boost::mpl::if_<
  60. boost::is_same<
  61. #endif
  62. T
  63. , typename X<
  64. test::keywords::tag::function_type
  65. , test::keywords::function_type<T>
  66. >::type
  67. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  68. >;
  69. #else
  70. >
  71. , boost::mpl::true_
  72. , boost::mpl::false_
  73. >::type
  74. {
  75. };
  76. #endif
  77. #else // MSVC-14.2
  78. struct Y
  79. {
  80. typedef typename boost::mpl::if_<
  81. boost::is_same<
  82. T
  83. , typename X<
  84. test::keywords::tag::function_type
  85. , test::keywords::function_type<T>
  86. >::type
  87. >
  88. , boost::mpl::true_
  89. , boost::mpl::false_
  90. >::type type;
  91. };
  92. #endif
  93. struct Z
  94. {
  95. int operator()() const
  96. {
  97. return 0;
  98. }
  99. };
  100. } // namespace test
  101. #include <boost/mpl/aux_/test.hpp>
  102. #if !defined(BOOST_PARAMETER_CAN_USE_MP11) || \
  103. BOOST_WORKAROUND(BOOST_MSVC, >= 1920)
  104. #include <boost/mpl/assert.hpp>
  105. #endif
  106. MPL_TEST_CASE()
  107. {
  108. #if BOOST_WORKAROUND(BOOST_MSVC, < 1920)
  109. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  110. static_assert(test::Y<void()>::value, "void()");
  111. static_assert(test::Y<test::Z>::value, "test::Z");
  112. static_assert(test::Y<double(double)>::value, "double(double)");
  113. #else
  114. BOOST_MPL_ASSERT((test::Y<void()>));
  115. BOOST_MPL_ASSERT((test::Y<test::Z>));
  116. BOOST_MPL_ASSERT((test::Y<double(double)>));
  117. #endif
  118. #else // MSVC-14.2
  119. BOOST_MPL_ASSERT((test::Y<void()>::type));
  120. BOOST_MPL_ASSERT((test::Y<test::Z>::type));
  121. BOOST_MPL_ASSERT((test::Y<double(double)>::type));
  122. #endif
  123. }