common_type_5_test.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. #endif
  10. #include "test.hpp"
  11. #include "check_type.hpp"
  12. #include <iostream>
  13. template<class T> struct X
  14. {
  15. T t_;
  16. X(): t_() {}
  17. template<class U> X( X<U> const & x ): t_( x.t_ ) {}
  18. };
  19. namespace boost
  20. {
  21. template<class T, class U> struct common_type< X<T>, X<U> >
  22. {
  23. typedef X<typename common_type<T, U>::type> type;
  24. };
  25. } // namespace boost
  26. TT_TEST_BEGIN(common_type_5)
  27. {
  28. // user specializations, binary
  29. BOOST_CHECK_TYPE3( tt::common_type< X<char>, X<char> >::type, X<char> );
  30. BOOST_CHECK_TYPE3( tt::common_type< X<char>&, X<char>& >::type, X<char> );
  31. BOOST_CHECK_TYPE3( tt::common_type< X<char>&, X<char> const& >::type, X<char> );
  32. BOOST_CHECK_TYPE3( tt::common_type< X<char> const&, X<char>& >::type, X<char> );
  33. BOOST_CHECK_TYPE3( tt::common_type< X<char> const&, X<char> const& >::type, X<char> );
  34. BOOST_CHECK_TYPE3( tt::common_type< X<char>, X<unsigned char> >::type, X<int> );
  35. BOOST_CHECK_TYPE3( tt::common_type< X<char>&, X<unsigned char>& >::type, X<int> );
  36. BOOST_CHECK_TYPE3( tt::common_type< X<char>&, X<unsigned char> const& >::type, X<int> );
  37. BOOST_CHECK_TYPE3( tt::common_type< X<char> const&, X<unsigned char>& >::type, X<int> );
  38. BOOST_CHECK_TYPE3( tt::common_type< X<char> const&, X<unsigned char> const& >::type, X<int> );
  39. // ternary
  40. BOOST_CHECK_TYPE4( tt::common_type< X<char>&, X<long> const&, X<short> volatile& >::type, X<long> );
  41. }
  42. TT_TEST_END