detected_or_test.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. Copyright 2017 Glen Joseph Fernandes
  3. (glenjofe@gmail.com)
  4. Distributed under the Boost Software License,
  5. Version 1.0. (See accompanying file LICENSE_1_0.txt
  6. or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. */
  8. #include <boost/config.hpp>
  9. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
  10. !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
  11. #ifdef TEST_STD
  12. #include <type_traits>
  13. #else
  14. #include <boost/type_traits/detected_or.hpp>
  15. #endif
  16. #include "check_integral_constant.hpp"
  17. #include "check_type.hpp"
  18. #define CHECK_FALSE(e) BOOST_CHECK_INTEGRAL_CONSTANT(e, false)
  19. #define CHECK_TRUE(e) BOOST_CHECK_INTEGRAL_CONSTANT(e, true)
  20. template<class T>
  21. using type_t = typename T::type;
  22. struct has_type {
  23. using type = char;
  24. };
  25. struct no_type { };
  26. TT_TEST_BEGIN(detected_or)
  27. CHECK_FALSE((::tt::detected_or<bool, type_t, int>::value_t::value));
  28. CHECK_TRUE((::tt::detected_or<bool, type_t, has_type>::value_t::value));
  29. CHECK_FALSE((::tt::detected_or<bool, type_t, no_type>::value_t::value));
  30. BOOST_CHECK_TYPE4(::tt::detected_or<bool, type_t, int>::type, bool);
  31. BOOST_CHECK_TYPE4(::tt::detected_or<bool, type_t, has_type>::type, char);
  32. BOOST_CHECK_TYPE4(::tt::detected_or<bool, type_t, no_type>::type, bool);
  33. BOOST_CHECK_TYPE4(::tt::detected_or_t<bool, type_t, int>, bool);
  34. BOOST_CHECK_TYPE4(::tt::detected_or_t<bool, type_t, has_type>, char);
  35. BOOST_CHECK_TYPE4(::tt::detected_or_t<bool, type_t, no_type>, bool);
  36. TT_TEST_END
  37. #else
  38. int main()
  39. {
  40. return 0;
  41. }
  42. #endif