forked from boostorg/type_traits
Add a few more common_type tests.
This commit is contained in:
22
test/common_type_3_test.cpp
Normal file
22
test/common_type_3_test.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
|
||||
// Copyright Peter Dimov 2015
|
||||
// Use, modification and distribution are subject to the
|
||||
// Boost Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.tt.org/LICENSE_1_0.txt)
|
||||
|
||||
#include "test.hpp"
|
||||
#include "check_type.hpp"
|
||||
#ifdef TEST_STD
|
||||
# include <type_traits>
|
||||
#else
|
||||
# include <boost/type_traits/common_type.hpp>
|
||||
#endif
|
||||
#include <iostream>
|
||||
|
||||
TT_TEST_BEGIN(common_type_3)
|
||||
{
|
||||
// just check whether the nullary specialization compiles
|
||||
tt::common_type<> tmp;
|
||||
(void)tmp;
|
||||
}
|
||||
TT_TEST_END
|
57
test/common_type_4_test.cpp
Normal file
57
test/common_type_4_test.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
|
||||
// Copyright Peter Dimov 2015
|
||||
// Use, modification and distribution are subject to the
|
||||
// Boost Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.tt.org/LICENSE_1_0.txt)
|
||||
|
||||
#include "test.hpp"
|
||||
#include "check_type.hpp"
|
||||
#ifdef TEST_STD
|
||||
# include <type_traits>
|
||||
#else
|
||||
# include <boost/type_traits/common_type.hpp>
|
||||
#endif
|
||||
#include <iostream>
|
||||
|
||||
TT_TEST_BEGIN(common_type_4)
|
||||
{
|
||||
// the unary case should be the same as decay
|
||||
|
||||
BOOST_CHECK_TYPE(tt::common_type<void>::type, void);
|
||||
BOOST_CHECK_TYPE(tt::common_type<void const>::type, void);
|
||||
BOOST_CHECK_TYPE(tt::common_type<void volatile>::type, void);
|
||||
BOOST_CHECK_TYPE(tt::common_type<void const volatile>::type, void);
|
||||
|
||||
BOOST_CHECK_TYPE(tt::common_type<char>::type, char);
|
||||
BOOST_CHECK_TYPE(tt::common_type<char const>::type, char);
|
||||
BOOST_CHECK_TYPE(tt::common_type<char volatile>::type, char);
|
||||
BOOST_CHECK_TYPE(tt::common_type<char const volatile>::type, char);
|
||||
|
||||
BOOST_CHECK_TYPE(tt::common_type<char&>::type, char);
|
||||
BOOST_CHECK_TYPE(tt::common_type<char const&>::type, char);
|
||||
BOOST_CHECK_TYPE(tt::common_type<char volatile&>::type, char);
|
||||
BOOST_CHECK_TYPE(tt::common_type<char const volatile&>::type, char);
|
||||
|
||||
BOOST_CHECK_TYPE(tt::common_type<char[]>::type, char*);
|
||||
BOOST_CHECK_TYPE(tt::common_type<char const[]>::type, char const*);
|
||||
BOOST_CHECK_TYPE(tt::common_type<char volatile[]>::type, char volatile*);
|
||||
BOOST_CHECK_TYPE(tt::common_type<char const volatile[]>::type, char const volatile*);
|
||||
|
||||
BOOST_CHECK_TYPE(tt::common_type<char[2]>::type, char*);
|
||||
BOOST_CHECK_TYPE(tt::common_type<char const[2]>::type, char const*);
|
||||
BOOST_CHECK_TYPE(tt::common_type<char volatile[2]>::type, char volatile*);
|
||||
BOOST_CHECK_TYPE(tt::common_type<char const volatile[2]>::type, char const volatile*);
|
||||
|
||||
BOOST_CHECK_TYPE(tt::common_type<char (&) [2]>::type, char*);
|
||||
BOOST_CHECK_TYPE(tt::common_type<char const (&) [2]>::type, char const*);
|
||||
BOOST_CHECK_TYPE(tt::common_type<char volatile (&) [2]>::type, char volatile*);
|
||||
BOOST_CHECK_TYPE(tt::common_type<char const volatile (&) [2]>::type, char const volatile*);
|
||||
|
||||
BOOST_CHECK_TYPE(tt::common_type<char()>::type, char(*)());
|
||||
|
||||
BOOST_CHECK_TYPE(tt::common_type<UDT()>::type, UDT(*)());
|
||||
BOOST_CHECK_TYPE(tt::common_type<UDT const()>::type, UDT const(*)());
|
||||
BOOST_CHECK_TYPE(tt::common_type<UDT volatile()>::type, UDT volatile(*)());
|
||||
BOOST_CHECK_TYPE(tt::common_type<UDT const volatile()>::type, UDT const volatile(*)());
|
||||
}
|
||||
TT_TEST_END
|
56
test/common_type_5_test.cpp
Normal file
56
test/common_type_5_test.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
|
||||
// Copyright Peter Dimov 2015
|
||||
// Use, modification and distribution are subject to the
|
||||
// Boost Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.tt.org/LICENSE_1_0.txt)
|
||||
|
||||
#include "test.hpp"
|
||||
#include "check_type.hpp"
|
||||
#ifdef TEST_STD
|
||||
# include <type_traits>
|
||||
#else
|
||||
# include <boost/type_traits/common_type.hpp>
|
||||
#endif
|
||||
#include <iostream>
|
||||
|
||||
template<class T> struct X
|
||||
{
|
||||
T t_;
|
||||
|
||||
X(): t_() {}
|
||||
template<class U> X( X<U> const & x ): t_( x.t_ ) {}
|
||||
};
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
template<class T, class U> struct common_type< X<T>, X<U> >
|
||||
{
|
||||
typedef X<typename common_type<T, U>::type> type;
|
||||
};
|
||||
|
||||
} // namespace boost
|
||||
|
||||
TT_TEST_BEGIN(common_type_5)
|
||||
{
|
||||
// user specializations, binary
|
||||
|
||||
BOOST_CHECK_TYPE3( tt::common_type< X<char>, X<char> >::type, X<char> );
|
||||
|
||||
BOOST_CHECK_TYPE3( tt::common_type< X<char>&, X<char>& >::type, X<char> );
|
||||
BOOST_CHECK_TYPE3( tt::common_type< X<char>&, X<char> const& >::type, X<char> );
|
||||
BOOST_CHECK_TYPE3( tt::common_type< X<char> const&, X<char>& >::type, X<char> );
|
||||
BOOST_CHECK_TYPE3( tt::common_type< X<char> const&, X<char> const& >::type, X<char> );
|
||||
|
||||
BOOST_CHECK_TYPE3( tt::common_type< X<char>, X<unsigned char> >::type, X<int> );
|
||||
|
||||
BOOST_CHECK_TYPE3( tt::common_type< X<char>&, X<unsigned char>& >::type, X<int> );
|
||||
BOOST_CHECK_TYPE3( tt::common_type< X<char>&, X<unsigned char> const& >::type, X<int> );
|
||||
BOOST_CHECK_TYPE3( tt::common_type< X<char> const&, X<unsigned char>& >::type, X<int> );
|
||||
BOOST_CHECK_TYPE3( tt::common_type< X<char> const&, X<unsigned char> const& >::type, X<int> );
|
||||
|
||||
// ternary
|
||||
|
||||
BOOST_CHECK_TYPE4( tt::common_type< X<char>&, X<long> const&, X<short> volatile& >::type, X<long> );
|
||||
}
|
||||
TT_TEST_END
|
Reference in New Issue
Block a user