common_type_sfinae2_test.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright Peter Dimov 2015
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.tt.org/LICENSE_1_0.txt)
  5. #ifdef TEST_STD
  6. # include <type_traits>
  7. #else
  8. # include <boost/type_traits/common_type.hpp>
  9. # include <boost/type_traits/integral_constant.hpp>
  10. #endif
  11. #include "test.hpp"
  12. #include "check_integral_constant.hpp"
  13. #include <iostream>
  14. typedef char(&s1)[1];
  15. typedef char(&s2)[2];
  16. template<class T> s1 has_type_impl( typename T::type * );
  17. template<class T> s2 has_type_impl( ... );
  18. template<class T> struct has_type: tt::integral_constant<bool, sizeof(has_type_impl<T>(0)) == sizeof(s1)> {};
  19. struct X {};
  20. struct Y {};
  21. TT_TEST_BEGIN(common_type_sfinae2)
  22. {
  23. #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  24. BOOST_CHECK_INTEGRAL_CONSTANT( (has_type< tt::common_type<int, void*> >::value), false );
  25. BOOST_CHECK_INTEGRAL_CONSTANT( (has_type< tt::common_type<X, Y> >::value), false );
  26. BOOST_CHECK_INTEGRAL_CONSTANT( (has_type< tt::common_type<X&, int const*> >::value), false );
  27. BOOST_CHECK_INTEGRAL_CONSTANT( (has_type< tt::common_type<X, Y, int, void*> >::value), false );
  28. #endif
  29. }
  30. TT_TEST_END