From 01493e4acbe1417cdc9bb361f450916bc00c94cc Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 8 Jun 2015 01:34:06 +0300 Subject: [PATCH] Add a few more common_type tests. --- test/common_type_3_test.cpp | 22 ++++++++++++++ test/common_type_4_test.cpp | 57 +++++++++++++++++++++++++++++++++++++ test/common_type_5_test.cpp | 56 ++++++++++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+) create mode 100644 test/common_type_3_test.cpp create mode 100644 test/common_type_4_test.cpp create mode 100644 test/common_type_5_test.cpp diff --git a/test/common_type_3_test.cpp b/test/common_type_3_test.cpp new file mode 100644 index 0000000..fd228b8 --- /dev/null +++ b/test/common_type_3_test.cpp @@ -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 +#else +# include +#endif +#include + +TT_TEST_BEGIN(common_type_3) +{ + // just check whether the nullary specialization compiles + tt::common_type<> tmp; + (void)tmp; +} +TT_TEST_END diff --git a/test/common_type_4_test.cpp b/test/common_type_4_test.cpp new file mode 100644 index 0000000..3a6659f --- /dev/null +++ b/test/common_type_4_test.cpp @@ -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 +#else +# include +#endif +#include + +TT_TEST_BEGIN(common_type_4) +{ + // the unary case should be the same as decay + + BOOST_CHECK_TYPE(tt::common_type::type, void); + BOOST_CHECK_TYPE(tt::common_type::type, void); + BOOST_CHECK_TYPE(tt::common_type::type, void); + BOOST_CHECK_TYPE(tt::common_type::type, void); + + BOOST_CHECK_TYPE(tt::common_type::type, char); + BOOST_CHECK_TYPE(tt::common_type::type, char); + BOOST_CHECK_TYPE(tt::common_type::type, char); + BOOST_CHECK_TYPE(tt::common_type::type, char); + + BOOST_CHECK_TYPE(tt::common_type::type, char); + BOOST_CHECK_TYPE(tt::common_type::type, char); + BOOST_CHECK_TYPE(tt::common_type::type, char); + BOOST_CHECK_TYPE(tt::common_type::type, char); + + BOOST_CHECK_TYPE(tt::common_type::type, char*); + BOOST_CHECK_TYPE(tt::common_type::type, char const*); + BOOST_CHECK_TYPE(tt::common_type::type, char volatile*); + BOOST_CHECK_TYPE(tt::common_type::type, char const volatile*); + + BOOST_CHECK_TYPE(tt::common_type::type, char*); + BOOST_CHECK_TYPE(tt::common_type::type, char const*); + BOOST_CHECK_TYPE(tt::common_type::type, char volatile*); + BOOST_CHECK_TYPE(tt::common_type::type, char const volatile*); + + BOOST_CHECK_TYPE(tt::common_type::type, char*); + BOOST_CHECK_TYPE(tt::common_type::type, char const*); + BOOST_CHECK_TYPE(tt::common_type::type, char volatile*); + BOOST_CHECK_TYPE(tt::common_type::type, char const volatile*); + + BOOST_CHECK_TYPE(tt::common_type::type, char(*)()); + + BOOST_CHECK_TYPE(tt::common_type::type, UDT(*)()); + BOOST_CHECK_TYPE(tt::common_type::type, UDT const(*)()); + BOOST_CHECK_TYPE(tt::common_type::type, UDT volatile(*)()); + BOOST_CHECK_TYPE(tt::common_type::type, UDT const volatile(*)()); +} +TT_TEST_END diff --git a/test/common_type_5_test.cpp b/test/common_type_5_test.cpp new file mode 100644 index 0000000..0a0e237 --- /dev/null +++ b/test/common_type_5_test.cpp @@ -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 +#else +# include +#endif +#include + +template struct X +{ + T t_; + + X(): t_() {} + template X( X const & x ): t_( x.t_ ) {} +}; + +namespace boost +{ + + template struct common_type< X, X > + { + typedef X::type> type; + }; + +} // namespace boost + +TT_TEST_BEGIN(common_type_5) +{ + // user specializations, binary + + BOOST_CHECK_TYPE3( tt::common_type< X, X >::type, X ); + + BOOST_CHECK_TYPE3( tt::common_type< X&, X& >::type, X ); + BOOST_CHECK_TYPE3( tt::common_type< X&, X const& >::type, X ); + BOOST_CHECK_TYPE3( tt::common_type< X const&, X& >::type, X ); + BOOST_CHECK_TYPE3( tt::common_type< X const&, X const& >::type, X ); + + BOOST_CHECK_TYPE3( tt::common_type< X, X >::type, X ); + + BOOST_CHECK_TYPE3( tt::common_type< X&, X& >::type, X ); + BOOST_CHECK_TYPE3( tt::common_type< X&, X const& >::type, X ); + BOOST_CHECK_TYPE3( tt::common_type< X const&, X& >::type, X ); + BOOST_CHECK_TYPE3( tt::common_type< X const&, X const& >::type, X ); + + // ternary + + BOOST_CHECK_TYPE4( tt::common_type< X&, X const&, X volatile& >::type, X ); +} +TT_TEST_END