From 3435d48f0ec6ee139793b958b3dfc3d596471110 Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Sat, 17 Jan 2015 19:08:08 +0000 Subject: [PATCH] Add the remaining traits - only common_type still has dependencies to something other than Boost.Config. --- include/boost/aligned_storage.hpp | 18 + include/boost/type_traits.hpp | 100 ++++++ .../boost/type_traits/alignment_traits.hpp | 15 + .../boost/type_traits/arithmetic_traits.hpp | 20 ++ include/boost/type_traits/array_traits.hpp | 15 + include/boost/type_traits/common_type.hpp | 157 +++++++++ .../boost/type_traits/conversion_traits.hpp | 17 + include/boost/type_traits/cv_traits.hpp | 24 ++ .../type_traits/detail/common_type_imp.hpp | 333 ++++++++++++++++++ .../type_traits/has_nothrow_destructor.hpp | 20 ++ .../boost/type_traits/reference_traits.hpp | 15 + include/boost/type_traits/same_traits.hpp | 15 + .../boost/type_traits/transform_traits.hpp | 21 ++ test/common_type_2_test.cpp | 222 ++++++++++++ test/common_type_fail.cpp | 27 ++ test/common_type_test.cpp | 215 +++++++++++ test/tricky_incomplete_type_test.cpp | 37 ++ test/type_traits_test.cpp | 103 ++++++ 18 files changed, 1374 insertions(+) create mode 100644 include/boost/aligned_storage.hpp create mode 100644 include/boost/type_traits.hpp create mode 100644 include/boost/type_traits/alignment_traits.hpp create mode 100644 include/boost/type_traits/arithmetic_traits.hpp create mode 100644 include/boost/type_traits/array_traits.hpp create mode 100644 include/boost/type_traits/common_type.hpp create mode 100644 include/boost/type_traits/conversion_traits.hpp create mode 100644 include/boost/type_traits/cv_traits.hpp create mode 100644 include/boost/type_traits/detail/common_type_imp.hpp create mode 100644 include/boost/type_traits/has_nothrow_destructor.hpp create mode 100644 include/boost/type_traits/reference_traits.hpp create mode 100644 include/boost/type_traits/same_traits.hpp create mode 100644 include/boost/type_traits/transform_traits.hpp create mode 100644 test/common_type_2_test.cpp create mode 100644 test/common_type_fail.cpp create mode 100644 test/common_type_test.cpp create mode 100644 test/tricky_incomplete_type_test.cpp create mode 100644 test/type_traits_test.cpp diff --git a/include/boost/aligned_storage.hpp b/include/boost/aligned_storage.hpp new file mode 100644 index 0000000..f400fa9 --- /dev/null +++ b/include/boost/aligned_storage.hpp @@ -0,0 +1,18 @@ +//----------------------------------------------------------------------------- +// boost aligned_storage.hpp header file +// See http://www.boost.org for updates, documentation, and revision history. +//----------------------------------------------------------------------------- +// +// Copyright (c) 2002-2003 +// Eric Friedman, Itay Maman +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_ALIGNED_STORAGE_HPP +#define BOOST_ALIGNED_STORAGE_HPP + +#include + +#endif // BOOST_ALIGNED_STORAGE_HPP diff --git a/include/boost/type_traits.hpp b/include/boost/type_traits.hpp new file mode 100644 index 0000000..4c9d8eb --- /dev/null +++ b/include/boost/type_traits.hpp @@ -0,0 +1,100 @@ +// (C) Copyright John Maddock 2000. +// 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.boost.org/LICENSE_1_0.txt). +// +// See http://www.boost.org/libs/type_traits for most recent version including documentation. + +// See boost/type_traits/*.hpp for full copyright notices. + +#ifndef BOOST_TYPE_TRAITS_HPP +#define BOOST_TYPE_TRAITS_HPP + +#include "boost/type_traits/add_const.hpp" +#include "boost/type_traits/add_cv.hpp" +#include "boost/type_traits/add_lvalue_reference.hpp" +#include "boost/type_traits/add_pointer.hpp" +#include "boost/type_traits/add_reference.hpp" +#include "boost/type_traits/add_rvalue_reference.hpp" +#include "boost/type_traits/add_volatile.hpp" +#include "boost/type_traits/aligned_storage.hpp" +#include "boost/type_traits/alignment_of.hpp" +#include "boost/type_traits/common_type.hpp" +#include "boost/type_traits/conditional.hpp" +#include "boost/type_traits/decay.hpp" +#include "boost/type_traits/extent.hpp" +#include "boost/type_traits/floating_point_promotion.hpp" +#include "boost/type_traits/function_traits.hpp" +#if !defined(__BORLANDC__) && !defined(__CUDACC__) +#include "boost/type_traits/has_new_operator.hpp" +#endif +#include "boost/type_traits/has_nothrow_assign.hpp" +#include "boost/type_traits/has_nothrow_constructor.hpp" +#include "boost/type_traits/has_nothrow_copy.hpp" +#include "boost/type_traits/has_nothrow_destructor.hpp" +#include +#include "boost/type_traits/has_trivial_assign.hpp" +#include "boost/type_traits/has_trivial_constructor.hpp" +#include "boost/type_traits/has_trivial_copy.hpp" +#include "boost/type_traits/has_trivial_destructor.hpp" +#include "boost/type_traits/has_trivial_move_assign.hpp" +#include "boost/type_traits/has_trivial_move_constructor.hpp" +#include "boost/type_traits/has_virtual_destructor.hpp" +#include "boost/type_traits/is_abstract.hpp" +#include "boost/type_traits/is_arithmetic.hpp" +#include "boost/type_traits/is_array.hpp" +#include "boost/type_traits/is_base_and_derived.hpp" +#include "boost/type_traits/is_base_of.hpp" +#include "boost/type_traits/is_class.hpp" +#include +#include "boost/type_traits/is_compound.hpp" +#include "boost/type_traits/is_const.hpp" +#include "boost/type_traits/is_convertible.hpp" +#include "boost/type_traits/is_copy_constructible.hpp" +#include "boost/type_traits/is_copy_assignable.hpp" +#include "boost/type_traits/is_empty.hpp" +#include "boost/type_traits/is_enum.hpp" +#include "boost/type_traits/is_float.hpp" +#include "boost/type_traits/is_floating_point.hpp" +#include "boost/type_traits/is_function.hpp" +#include "boost/type_traits/is_fundamental.hpp" +#include "boost/type_traits/is_integral.hpp" +#include "boost/type_traits/is_lvalue_reference.hpp" +#include "boost/type_traits/is_member_function_pointer.hpp" +#include "boost/type_traits/is_member_object_pointer.hpp" +#include "boost/type_traits/is_member_pointer.hpp" +#include "boost/type_traits/is_nothrow_move_assignable.hpp" +#include "boost/type_traits/is_nothrow_move_constructible.hpp" +#include "boost/type_traits/is_object.hpp" +#include "boost/type_traits/is_pod.hpp" +#include "boost/type_traits/is_polymorphic.hpp" +#include "boost/type_traits/is_pointer.hpp" +#include "boost/type_traits/is_reference.hpp" +#include "boost/type_traits/is_rvalue_reference.hpp" +#include "boost/type_traits/is_signed.hpp" +#include "boost/type_traits/is_same.hpp" +#include "boost/type_traits/is_scalar.hpp" +#include "boost/type_traits/is_stateless.hpp" +#include "boost/type_traits/is_union.hpp" +#include "boost/type_traits/is_unsigned.hpp" +#include "boost/type_traits/is_void.hpp" +#include "boost/type_traits/is_virtual_base_of.hpp" +#include "boost/type_traits/is_volatile.hpp" +#include +#include +#include "boost/type_traits/rank.hpp" +#include "boost/type_traits/remove_bounds.hpp" +#include "boost/type_traits/remove_extent.hpp" +#include "boost/type_traits/remove_all_extents.hpp" +#include "boost/type_traits/remove_const.hpp" +#include "boost/type_traits/remove_cv.hpp" +#include "boost/type_traits/remove_pointer.hpp" +#include "boost/type_traits/remove_reference.hpp" +#include "boost/type_traits/remove_volatile.hpp" +#include "boost/type_traits/type_with_alignment.hpp" +#if !(defined(__sgi) && defined(__EDG_VERSION__) && (__EDG_VERSION__ == 238)) +#include "boost/type_traits/integral_promotion.hpp" +#include "boost/type_traits/promote.hpp" +#endif + +#endif // BOOST_TYPE_TRAITS_HPP diff --git a/include/boost/type_traits/alignment_traits.hpp b/include/boost/type_traits/alignment_traits.hpp new file mode 100644 index 0000000..2ed6934 --- /dev/null +++ b/include/boost/type_traits/alignment_traits.hpp @@ -0,0 +1,15 @@ + +// (C) Copyright John Maddock 2000. +// 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.boost.org/LICENSE_1_0.txt). +// +// See http://www.boost.org/libs/type_traits for most recent version including documentation. + +#ifndef BOOST_TT_ALIGNMENT_TRAITS_HPP_INCLUDED +#define BOOST_TT_ALIGNMENT_TRAITS_HPP_INCLUDED + +#include +#include + +#endif // BOOST_TT_ALIGNMENT_TRAITS_HPP_INCLUDED diff --git a/include/boost/type_traits/arithmetic_traits.hpp b/include/boost/type_traits/arithmetic_traits.hpp new file mode 100644 index 0000000..e4670e6 --- /dev/null +++ b/include/boost/type_traits/arithmetic_traits.hpp @@ -0,0 +1,20 @@ +// (C) Copyright Steve Cleary, Beman Dawes, Howard Hinnant & John Maddock 2000. +// 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.boost.org/LICENSE_1_0.txt). +// +// See http://www.boost.org/libs/type_traits for most recent version including documentation. +// +// defines traits classes for arithmetic types: +// is_void, is_integral, is_float, is_arithmetic, is_fundamental. + +#ifndef BOOST_TT_ARITHMETIC_TRAITS_HPP_INCLUDED +#define BOOST_TT_ARITHMETIC_TRAITS_HPP_INCLUDED + +#include +#include +#include +#include +#include + +#endif // BOOST_TT_ARITHMETIC_TRAITS_HPP_INCLUDED diff --git a/include/boost/type_traits/array_traits.hpp b/include/boost/type_traits/array_traits.hpp new file mode 100644 index 0000000..a68ae73 --- /dev/null +++ b/include/boost/type_traits/array_traits.hpp @@ -0,0 +1,15 @@ +// (C) Copyright Dave Abrahams, Steve Cleary, Beman Dawes, Howard +// Hinnant & John Maddock 2000. +// 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.boost.org/LICENSE_1_0.txt). +// +// See http://www.boost.org/libs/type_traits for most recent version including documentation. + + +#ifndef BOOST_TT_ARRAY_TRAITS_HPP_INCLUDED +#define BOOST_TT_ARRAY_TRAITS_HPP_INCLUDED + +#include + +#endif // BOOST_TT_ARRAY_TRAITS_HPP_INCLUDED diff --git a/include/boost/type_traits/common_type.hpp b/include/boost/type_traits/common_type.hpp new file mode 100644 index 0000000..b52ff16 --- /dev/null +++ b/include/boost/type_traits/common_type.hpp @@ -0,0 +1,157 @@ +// common_type.hpp ---------------------------------------------------------// + +// Copyright 2008 Howard Hinnant +// Copyright 2008 Beman Dawes + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#ifndef BOOST_TYPE_TRAITS_COMMON_TYPE_HPP +#define BOOST_TYPE_TRAITS_COMMON_TYPE_HPP + +#include + +#if defined(__SUNPRO_CC) && !defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF) +# define BOOST_COMMON_TYPE_DONT_USE_TYPEOF +#endif +#if defined(__IBMCPP__) && !defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF) +# define BOOST_COMMON_TYPE_DONT_USE_TYPEOF +#endif + +//----------------------------------------------------------------------------// +#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_COMMON_TYPE_ARITY) +#define BOOST_COMMON_TYPE_ARITY 3 +#endif + +//----------------------------------------------------------------------------// +#if defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF) +#include // boost wonders never cease! +#endif + +//----------------------------------------------------------------------------// +#ifndef BOOST_NO_CXX11_STATIC_ASSERT +#define BOOST_COMMON_TYPE_STATIC_ASSERT(CND, MSG, TYPES) static_assert(CND,MSG) +#elif defined(BOOST_COMMON_TYPE_USES_MPL_ASSERT) +#include +#include +#define BOOST_COMMON_TYPE_STATIC_ASSERT(CND, MSG, TYPES) \ + BOOST_MPL_ASSERT_MSG(boost::mpl::bool_< (CND) >::type::value, MSG, TYPES) +#else +#include +#define BOOST_COMMON_TYPE_STATIC_ASSERT(CND, MSG, TYPES) BOOST_STATIC_ASSERT(CND) +#endif + +#if !defined(BOOST_NO_CXX11_STATIC_ASSERT) || !defined(BOOST_COMMON_TYPE_USES_MPL_ASSERT) +#define BOOST_COMMON_TYPE_MUST_BE_A_COMPLE_TYPE "must be complete type" +#endif + +#if defined(BOOST_NO_CXX11_DECLTYPE) && defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF) +#include +#include +#endif +#include +#include +#include + +//----------------------------------------------------------------------------// +// // +// C++03 implementation of // +// 20.9.7.6 Other transformations [meta.trans.other] // +// Written by Howard Hinnant // +// Adapted for Boost by Beman Dawes, Vicente Botet and Jeffrey Hellrung // +// // +//----------------------------------------------------------------------------// + +namespace boost { + +// prototype +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + template + struct common_type; +#else // or no specialization + template + struct common_type + { + public: + typedef typename common_type::type, V>::type type; + }; +#endif + + +// 1 arg + template +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + struct common_type +#else + struct common_type + +#endif + { + BOOST_COMMON_TYPE_STATIC_ASSERT(sizeof(T) > 0, BOOST_COMMON_TYPE_MUST_BE_A_COMPLE_TYPE, (T)); + public: + typedef T type; + }; + +// 2 args +namespace type_traits_detail { + + template + struct common_type_2 + { + private: + BOOST_COMMON_TYPE_STATIC_ASSERT(sizeof(T) > 0, BOOST_COMMON_TYPE_MUST_BE_A_COMPLE_TYPE, (T)); + BOOST_COMMON_TYPE_STATIC_ASSERT(sizeof(U) > 0, BOOST_COMMON_TYPE_MUST_BE_A_COMPLE_TYPE, (U)); + static bool declval_bool(); // workaround gcc bug; not required by std + static typename add_rvalue_reference::type declval_T(); // workaround gcc bug; not required by std + static typename add_rvalue_reference::type declval_U(); // workaround gcc bug; not required by std + static typename add_rvalue_reference::type declval_b(); + +#if !defined(BOOST_NO_CXX11_DECLTYPE) + public: + typedef decltype(declval() ? declval() : declval()) type; +#elif defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF) + public: + typedef typename detail_type_traits_common_type::common_type_impl< + typename remove_cv::type, + typename remove_cv::type + >::type type; +#else + public: + typedef BOOST_TYPEOF_TPL(declval_b() ? declval_T() : declval_U()) type; +#endif + +#if defined(__GNUC__) && __GNUC__ == 3 && __GNUC_MINOR__ == 3 + public: + void public_dummy_function_just_to_silence_warning(); +#endif + }; + + template + struct common_type_2 + { + typedef T type; + }; + } + +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + template + struct common_type +#else + template + struct common_type +#endif + : public type_traits_detail::common_type_2 + { }; + + +// 3 or more args +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + template + struct common_type { + public: + typedef typename common_type::type, V...>::type type; + }; +#endif +} // namespace boost + +#endif // BOOST_TYPE_TRAITS_COMMON_TYPE_HPP diff --git a/include/boost/type_traits/conversion_traits.hpp b/include/boost/type_traits/conversion_traits.hpp new file mode 100644 index 0000000..c8e5139 --- /dev/null +++ b/include/boost/type_traits/conversion_traits.hpp @@ -0,0 +1,17 @@ + +// Copyright 2000 John Maddock (john@johnmaddock.co.uk) +// Copyright 2000 Jeremy Siek (jsiek@lsc.nd.edu) +// Copyright 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi) +// +// 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.boost.org/LICENSE_1_0.txt). +// +// See http://www.boost.org/libs/type_traits for most recent version including documentation. + +#ifndef BOOST_TT_CONVERSION_TRAITS_HPP_INCLUDED +#define BOOST_TT_CONVERSION_TRAITS_HPP_INCLUDED + +#include + +#endif // BOOST_TT_CONVERSION_TRAITS_HPP_INCLUDED diff --git a/include/boost/type_traits/cv_traits.hpp b/include/boost/type_traits/cv_traits.hpp new file mode 100644 index 0000000..5bd6c4f --- /dev/null +++ b/include/boost/type_traits/cv_traits.hpp @@ -0,0 +1,24 @@ +// (C) Copyright Dave Abrahams, Steve Cleary, Beman Dawes, Howard +// Hinnant & John Maddock 2000. +// 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.boost.org/LICENSE_1_0.txt). +// +// See http://www.boost.org/libs/type_traits for most recent version including documentation. +// +// defines traits classes for cv-qualified types: +// is_const, is_volatile, remove_const, remove_volatile, remove_cv. + +#ifndef BOOST_TT_CV_TRAITS_HPP_INCLUDED +#define BOOST_TT_CV_TRAITS_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include +#include +#include + +#endif // BOOST_TT_CV_TRAITS_HPP_INCLUDED diff --git a/include/boost/type_traits/detail/common_type_imp.hpp b/include/boost/type_traits/detail/common_type_imp.hpp new file mode 100644 index 0000000..84de8b4 --- /dev/null +++ b/include/boost/type_traits/detail/common_type_imp.hpp @@ -0,0 +1,333 @@ +/******************************************************************************* + * boost/type_traits/detail/common_type_imp.hpp + * + * Copyright 2010, Jeffrey Hellrung. + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + * + * struct boost::common_type + * + * common_type::type is the type of the expression + * b() ? x() : y() + * where b() returns a bool, x() has return type T, and y() has return type U. + * See + * http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2661.htm#common_type + * + * Note that this evaluates to void if one or both of T and U is void. + ******************************************************************************/ + +#ifndef BOOST_TYPE_TRAITS_DETAIL_COMMON_TYPE_IMP_HPP +#define BOOST_TYPE_TRAITS_DETAIL_COMMON_TYPE_IMP_HPP + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + +namespace detail_type_traits_common_type +{ + +/******************************************************************************* + * struct propagate_cv< From, To > + * + * This metafunction propagates cv-qualifiers on type From to type To. + ******************************************************************************/ + +template< class From, class To > +struct propagate_cv +{ typedef To type; }; +template< class From, class To > +struct propagate_cv< const From, To > +{ typedef To const type; }; +template< class From, class To > +struct propagate_cv< volatile From, To > +{ typedef To volatile type; }; +template< class From, class To > +struct propagate_cv< const volatile From, To > +{ typedef To const volatile type; }; + +/******************************************************************************* + * struct is_integral_or_enum + * + * This metafunction determines if T is an integral type which can be made + * signed or unsigned. + ******************************************************************************/ + +template< class T > +struct is_integral_or_enum + : public mpl::or_< is_integral, is_enum > +{ }; +template<> +struct is_integral_or_enum< bool > + : public false_type +{ }; + +/******************************************************************************* + * struct make_unsigned_soft + * struct make_signed_soft + * + * These metafunction are identical to make_unsigned and make_signed, + * respectively, except for special-casing bool. + ******************************************************************************/ + +template< class T > +struct make_unsigned_soft + : public make_unsigned +{ }; +template<> +struct make_unsigned_soft< bool > +{ typedef bool type; }; + +template< class T > +struct make_signed_soft + : public make_signed +{ }; +template<> +struct make_signed_soft< bool > +{ typedef bool type; }; + +/******************************************************************************* + * struct sizeof_t + * typedef ... yes_type + * typedef ... no_type + * + * These types are integral players in the use of the "sizeof trick", i.e., we + * can distinguish overload selection by inspecting the size of the return type + * of the overload. + ******************************************************************************/ + +template< std::size_t N > struct sizeof_t { char _dummy[N]; }; +typedef sizeof_t<1> yes_type; +typedef sizeof_t<2> no_type; +BOOST_MPL_ASSERT_RELATION( sizeof( yes_type ), ==, 1 ); +BOOST_MPL_ASSERT_RELATION( sizeof( no_type ), ==, 2 ); + +/******************************************************************************* + * rvalue_test(T&) -> no_type + * rvalue_test(...) -> yes_type + * + * These overloads are used to determine the rvalue-ness of an expression. + ******************************************************************************/ + +template< class T > no_type rvalue_test(T&); +yes_type rvalue_test(...); + +/******************************************************************************* + * struct conversion_test_overloads< Sequence > + * + * This struct has multiple overloads of the static member function apply, each + * one taking a single parameter of a type within the Boost.MPL sequence + * Sequence. Each such apply overload has a return type with sizeof equal to + * one plus the index of the parameter type within Sequence. Thus, we can + * deduce the type T of an expression as long as we can generate a finite set of + * candidate types containing T via these apply overloads and the "sizeof + * trick". + ******************************************************************************/ + +template< class First, class Last, std::size_t Index > +struct conversion_test_overloads_iterate + : public conversion_test_overloads_iterate< + typename mpl::next< First >::type, Last, Index + 1 + > +{ + using conversion_test_overloads_iterate< + typename mpl::next< First >::type, Last, Index + 1 + >::apply; + static sizeof_t< Index + 1 > + apply(typename mpl::deref< First >::type); +}; + +template< class Last, std::size_t Index > +struct conversion_test_overloads_iterate< Last, Last, Index > +{ static sizeof_t< Index + 1 > apply(...); }; + +template< class Sequence > +struct conversion_test_overloads + : public conversion_test_overloads_iterate< + typename mpl::begin< Sequence >::type, + typename mpl::end< Sequence >::type, + 0 + > +{ }; + +/******************************************************************************* + * struct select< Sequence, Index > + * + * select is synonymous with mpl::at_c unless Index equals the size of the + * Boost.MPL Sequence, in which case this evaluates to void. + ******************************************************************************/ + +template< + class Sequence, int Index, + int N = mpl::size< Sequence >::value +> +struct select + : public mpl::at_c< Sequence, Index > +{ }; +template< class Sequence, int N > +struct select< Sequence, N, N > +{ typedef void type; }; + +/******************************************************************************* + * class deduce_common_type< T, U, NominalCandidates > + * struct nominal_candidates + * struct common_type_dispatch_on_rvalueness + * struct common_type_impl + * + * These classes and structs implement the logic behind common_type, which goes + * roughly as follows. Let C be the type of the conditional expression + * declval< bool >() ? declval() : declval() + * if C is an rvalue, then: + * let T' and U' be T and U stripped of reference- and cv-qualifiers + * if T' and U' are pointer types, say, T' = V* and U' = W*, then: + * define the set of NominalCandidates to be + * { V*, W*, V'*, W'* } + * where V' is V with whatever cv-qualifiers are on W, and W' is W + * with whatever cv-qualifiers are on V + * else if T' and U' are both integral or enum types, then: + * define the set of NominalCandidates to be + * { + * unsigned_soft(T'), + * unsigned_soft(U'), + * signed_soft(T'), + * signed_soft(U'), + * T', + * U', + * unsigned int, + * int + * } + * where unsigned_soft(X) is make_unsigned_soft::type and + * signed_soft(X) is make_signed_soft::type (these are all + * generally necessary to cover the various integral promotion cases) + * else + * define the set of NominalCandidates to be + * { T', U' } + * else + * let V and W be T and U stripped of reference-qualifiers + * define the set of NominalCandidates to be + * { V&, W&, V'&, W'& } + * where V' is V with whatever cv-qualifiers are on W, and W' is W with + * whatever cv-qualifiers are on V + * define the set of Candidates to be equal to the set of NominalCandidates with + * duplicates removed, and use this set of Candidates to determine C using the + * conversion_test_overloads struct + ******************************************************************************/ + +template< class T, class U, class NominalCandidates > +class deduce_common_type +{ + typedef typename mpl::copy< + NominalCandidates, + mpl::inserter< + mpl::vector0<>, + mpl::if_< + mpl::contains< mpl::_1, mpl::_2 >, + mpl::_1, + mpl::push_back< mpl::_1, mpl::_2 > + > + > + >::type candidate_types; + static const int best_candidate_index = + sizeof( conversion_test_overloads< candidate_types >::apply( + declval< bool >() ? declval() : declval() + ) ) - 1; +public: + typedef typename select< candidate_types, best_candidate_index >::type type; +}; + +template< + class T, class U, + class V = typename remove_cv< typename remove_reference::type >::type, + class W = typename remove_cv< typename remove_reference::type >::type, + bool = is_integral_or_enum::value && is_integral_or_enum::value +> +struct nominal_candidates +{ typedef mpl::vector2 type; }; + +template< class T, class U, class V, class W > +struct nominal_candidates< T, U, V, W, true > +{ + typedef boost::mpl::vector8< + typename make_unsigned_soft::type, + typename make_unsigned_soft::type, + typename make_signed_soft::type, + typename make_signed_soft::type, + V, W, unsigned int, int + > type; +}; + +template< class T, class U, class V, class W > +struct nominal_candidates< T, U, V*, W*, false > +{ + typedef mpl::vector4< + V*, W*, + typename propagate_cv::type *, + typename propagate_cv::type * + > type; +}; + +template +struct common_type_dispatch_on_rvalueness + : public deduce_common_type< T, U, typename nominal_candidates::type > +{ }; + +template< class T, class U > +struct common_type_dispatch_on_rvalueness< T, U, false > +{ +private: + typedef typename remove_reference::type unrefed_T_type; + typedef typename remove_reference::type unrefed_U_type; +public: + typedef typename deduce_common_type< + T, U, + mpl::vector4< + unrefed_T_type &, + unrefed_U_type &, + typename propagate_cv< unrefed_U_type, unrefed_T_type >::type &, + typename propagate_cv< unrefed_T_type, unrefed_U_type >::type & + > + >::type type; +}; + +template< class T, class U > +struct common_type_impl + : public common_type_dispatch_on_rvalueness() ? declval() : declval() ) ) == sizeof( yes_type ) > +{ }; + +template< class T > struct common_type_impl< T, void > { typedef void type; }; +template< class T > struct common_type_impl< void, T > { typedef void type; }; +template<> struct common_type_impl< void, void > { typedef void type; }; + +} // namespace detail_type_traits_common_type + + +} // namespace boost + +#endif // BOOST_TYPE_TRAITS_DETAIL_COMMON_TYPE_HPP + diff --git a/include/boost/type_traits/has_nothrow_destructor.hpp b/include/boost/type_traits/has_nothrow_destructor.hpp new file mode 100644 index 0000000..e510ece --- /dev/null +++ b/include/boost/type_traits/has_nothrow_destructor.hpp @@ -0,0 +1,20 @@ + +// (C) Copyright Steve Cleary, Beman Dawes, Howard Hinnant & John Maddock 2000. +// 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.boost.org/LICENSE_1_0.txt). +// +// See http://www.boost.org/libs/type_traits for most recent version including documentation. + +#ifndef BOOST_TT_HAS_NOTHROW_DESTRUCTOR_HPP_INCLUDED +#define BOOST_TT_HAS_NOTHROW_DESTRUCTOR_HPP_INCLUDED + +#include + +namespace boost { + +template struct has_nothrow_destructor : public ::boost::has_trivial_destructor {}; + +} // namespace boost + +#endif // BOOST_TT_HAS_NOTHROW_DESTRUCTOR_HPP_INCLUDED diff --git a/include/boost/type_traits/reference_traits.hpp b/include/boost/type_traits/reference_traits.hpp new file mode 100644 index 0000000..1607b3d --- /dev/null +++ b/include/boost/type_traits/reference_traits.hpp @@ -0,0 +1,15 @@ +// (C) Copyright David Abrahams Steve Cleary, Beman Dawes, Howard +// Hinnant & John Maddock 2000-2002. +// 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.boost.org/LICENSE_1_0.txt). +// +// See http://www.boost.org/libs/type_traits for most recent version including documentation. + + +#ifndef BOOST_TT_REFERENCE_TRAITS_HPP_INCLUDED +#define BOOST_TT_REFERENCE_TRAITS_HPP_INCLUDED + +#include + +#endif // BOOST_TT_REFERENCE_TRAITS_HPP_INCLUDED diff --git a/include/boost/type_traits/same_traits.hpp b/include/boost/type_traits/same_traits.hpp new file mode 100644 index 0000000..dab7dac --- /dev/null +++ b/include/boost/type_traits/same_traits.hpp @@ -0,0 +1,15 @@ +// (C) Copyright Steve Cleary, Beman Dawes, Aleksey Gurtovoy, Howard Hinnant & John Maddock 2000. +// 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.boost.org/LICENSE_1_0.txt). +// +// See http://www.boost.org/libs/type_traits for most recent version including documentation. +// +// defines is_same: + +#ifndef BOOST_TT_SAME_TRAITS_HPP_INCLUDED +#define BOOST_TT_SAME_TRAITS_HPP_INCLUDED + +#include + +#endif // BOOST_TT_SAME_TRAITS_HPP_INCLUDED diff --git a/include/boost/type_traits/transform_traits.hpp b/include/boost/type_traits/transform_traits.hpp new file mode 100644 index 0000000..7a82f1c --- /dev/null +++ b/include/boost/type_traits/transform_traits.hpp @@ -0,0 +1,21 @@ +// (C) Copyright Steve Cleary, Beman Dawes, Howard Hinnant & John Maddock 2000. +// 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.boost.org/LICENSE_1_0.txt). +// +// See http://www.boost.org/libs/type_traits for most recent version including documentation. +// +// defines traits classes for transforming one type to another: +// remove_reference, add_reference, remove_bounds, remove_pointer. +// + +#ifndef BOOST_TT_TRANSFORM_TRAITS_HPP_INCLUDED +#define BOOST_TT_TRANSFORM_TRAITS_HPP_INCLUDED + +#include +#include +#include +#include +#include + +#endif // BOOST_TT_TRANSFORM_TRAITS_HPP_INCLUDED diff --git a/test/common_type_2_test.cpp b/test/common_type_2_test.cpp new file mode 100644 index 0000000..8a4e746 --- /dev/null +++ b/test/common_type_2_test.cpp @@ -0,0 +1,222 @@ +// common_type_test.cpp ----------------------------------------------------// + +// Copyright 2010 Beman Dawes + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#define BOOST_COMMON_TYPE_DONT_USE_TYPEOF 1 + +#include "test.hpp" +#include "check_type.hpp" +#ifdef TEST_STD +# include +#else +# include +#endif +#include + +#ifdef BOOST_INTEL +#pragma warning(disable: 304 383) +#endif + +struct C1 {}; + +struct C2 {}; + + +struct C3 : C2 {}; +struct C1C2 { + C1C2() {} + C1C2(C1 const&) {} + C1C2(C2 const&) {} + C1C2& operator=(C1C2 const&) { + return *this; + } +}; + +template +void proc2(typename boost::common_type::type const& ) {} + +template +void proc3(typename boost::common_type::type const& ) {} + +template +void assignation_2() { +typedef typename boost::common_type::type AC; + A a; + C c; + AC ac; + ac=a; + ac=c; + + proc2(a); + proc2(c); + +} + +template +void assignation_3() { +typedef typename boost::common_type::type ABC; + A a; + B b; + C c; + ABC abc; + + abc=a; + abc=b; + abc=c; + + proc3(a); + proc3(b); + proc3(c); +} + +C1C2 c1c2; +C1 c1; + +int f(C1C2 ) { return 1;} +int f(C1 ) { return 2;} +template +OSTREAM& operator<<(OSTREAM& os, C1 const&) {return os;} + +C1C2& declval_C1C2() {return c1c2;} +C1& declval_C1(){return c1;} +bool declval_bool(){return true;} + + +TT_TEST_BEGIN(common_type) +{ +#ifndef __SUNPRO_CC + assignation_2(); + typedef tt::common_type::type T1; + BOOST_CHECK_TYPE(T1, C1C2); + typedef tt::common_type::type T2; + BOOST_CHECK_TYPE(T2, C2*); + typedef tt::common_type::type T3; + BOOST_CHECK_TYPE(T3, int const*); +#if defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF) + // fails if BOOST_COMMON_TYPE_DONT_USE_TYPEOF: + typedef tt::common_type::type T4; + BOOST_CHECK_TYPE(T4, int const volatile*); +#endif + typedef tt::common_type::type T5; + BOOST_CHECK_TYPE(T5, int volatile*); + + assignation_2(); + assignation_2(); + assignation_2(); + assignation_3(); + assignation_3(); + assignation_3(); + assignation_3(); + //assignation_3(); // fails because the common type is the third +#endif + + typedef tt::common_type::type t1; + BOOST_CHECK_TYPE(t1, C1C2); + + BOOST_CHECK_TYPE(tt::common_type::type, int); + BOOST_CHECK_TYPE(tt::common_type::type, char); + + BOOST_CHECK_TYPE3(tt::common_type::type, char); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); +#ifndef BOOST_NO_LONG_LONG + BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); + BOOST_CHECK_TYPE3(tt::common_type::type, boost::ulong_long_type); +#endif + BOOST_CHECK_TYPE3(tt::common_type::type, double); + + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, unsigned char); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); +#ifndef BOOST_NO_LONG_LONG + BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); + BOOST_CHECK_TYPE3(tt::common_type::type, boost::ulong_long_type); +#endif + BOOST_CHECK_TYPE3(tt::common_type::type, double); + + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, short); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); +#ifndef BOOST_NO_LONG_LONG + BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); + BOOST_CHECK_TYPE3(tt::common_type::type, boost::ulong_long_type); +#endif + BOOST_CHECK_TYPE3(tt::common_type::type, double); + + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, unsigned short); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); +#ifndef BOOST_NO_LONG_LONG + BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); + BOOST_CHECK_TYPE3(tt::common_type::type, boost::ulong_long_type); +#endif + BOOST_CHECK_TYPE3(tt::common_type::type, double); + + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); +#ifndef BOOST_NO_LONG_LONG + BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); + BOOST_CHECK_TYPE3(tt::common_type::type, boost::ulong_long_type); +#endif + BOOST_CHECK_TYPE3(tt::common_type::type, double); + + BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); + BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); + BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); + BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); + BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); + BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); +#ifndef BOOST_NO_LONG_LONG + BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); + BOOST_CHECK_TYPE3(tt::common_type::type, boost::ulong_long_type); +#endif + BOOST_CHECK_TYPE3(tt::common_type::type, double); + +#ifndef BOOST_NO_LONG_LONG + BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); + BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); + BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); + BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); + BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); + BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); + BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); + BOOST_CHECK_TYPE3(tt::common_type::type, boost::ulong_long_type); + BOOST_CHECK_TYPE3(tt::common_type::type, double); +#endif + BOOST_CHECK_TYPE3(tt::common_type::type, double); + BOOST_CHECK_TYPE3(tt::common_type::type, double); + BOOST_CHECK_TYPE3(tt::common_type::type, double); + BOOST_CHECK_TYPE3(tt::common_type::type, double); + BOOST_CHECK_TYPE3(tt::common_type::type, double); + BOOST_CHECK_TYPE3(tt::common_type::type, double); +#ifndef BOOST_NO_LONG_LONG + BOOST_CHECK_TYPE3(tt::common_type::type, double); + BOOST_CHECK_TYPE3(tt::common_type::type, double); +#endif + BOOST_CHECK_TYPE3(tt::common_type::type, double); + + BOOST_CHECK_TYPE4(tt::common_type::type, double); +#ifndef BOOST_NO_LONG_LONG + BOOST_CHECK_TYPE4(tt::common_type::type, boost::long_long_type); +#endif +} +TT_TEST_END diff --git a/test/common_type_fail.cpp b/test/common_type_fail.cpp new file mode 100644 index 0000000..2b52252 --- /dev/null +++ b/test/common_type_fail.cpp @@ -0,0 +1,27 @@ +// common_type_test.cpp ----------------------------------------------------// + +// Copyright 2010 Beman Dawes + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#define _CRT_SECURE_NO_WARNINGS // disable VC++ foolishness + +#include "test.hpp" +#ifndef TEST_STD +#include +#else +#include +#endif + +struct C1 { + //~ private: + //~ C1(); +}; + +struct C2 {}; + + + +typedef tt::common_type::type AC; + diff --git a/test/common_type_test.cpp b/test/common_type_test.cpp new file mode 100644 index 0000000..111cbb1 --- /dev/null +++ b/test/common_type_test.cpp @@ -0,0 +1,215 @@ +// common_type_test.cpp ----------------------------------------------------// + +// Copyright 2010 Beman Dawes + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include "test.hpp" +#include "check_type.hpp" +#ifdef TEST_STD +# include +#else +# include +#endif +#include + +#ifdef BOOST_INTEL +#pragma warning(disable: 304 383) +#endif + +struct C1 {}; + +struct C2 {}; + + +struct C3 : C2 {}; +struct C1C2 { + C1C2() {} + C1C2(C1 const&) {} + C1C2(C2 const&) {} + C1C2& operator=(C1C2 const&) { + return *this; + } +}; + +template +void proc2(typename boost::common_type::type const& ) {} + +template +void proc3(typename boost::common_type::type const& ) {} + +template +void assignation_2() { +typedef typename boost::common_type::type AC; + A a; + C c; + AC ac; + ac=a; + ac=c; + + proc2(a); + proc2(c); + +} + +template +void assignation_3() { +typedef typename boost::common_type::type ABC; + A a; + B b; + C c; + ABC abc; + + abc=a; + abc=b; + abc=c; + + proc3(a); + proc3(b); + proc3(c); +} + +C1C2 c1c2; +C1 c1; + +int f(C1C2 ) { return 1;} +int f(C1 ) { return 2;} +template +OSTREAM& operator<<(OSTREAM& os, C1 const&) {return os;} + +C1C2& declval_C1C2() {return c1c2;} +C1& declval_C1(){return c1;} +bool declval_bool(){return true;} + + +TT_TEST_BEGIN(common_type) +{ + assignation_2(); + typedef tt::common_type::type T1; + BOOST_CHECK_TYPE(T1, C1C2); + typedef tt::common_type::type T2; + BOOST_CHECK_TYPE(T2, C2*); + typedef tt::common_type::type T3; + BOOST_CHECK_TYPE(T3, int const*); +#if defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF) + // fails if BOOST_COMMON_TYPE_DONT_USE_TYPEOF: + typedef tt::common_type::type T4; + BOOST_CHECK_TYPE(T4, int const volatile*); +#endif + typedef tt::common_type::type T5; + BOOST_CHECK_TYPE(T5, int volatile*); + + assignation_2(); + assignation_2(); + assignation_2(); + assignation_3(); + assignation_3(); + assignation_3(); + assignation_3(); + //assignation_3(); // fails because the common type is the third + + BOOST_CHECK_TYPE(tt::common_type::type, int); + BOOST_CHECK_TYPE(tt::common_type::type, char); + + BOOST_CHECK_TYPE3(tt::common_type::type, char); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); +#ifndef BOOST_NO_LONG_LONG + BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); + BOOST_CHECK_TYPE3(tt::common_type::type, boost::ulong_long_type); +#endif + BOOST_CHECK_TYPE3(tt::common_type::type, double); + + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, unsigned char); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); +#ifndef BOOST_NO_LONG_LONG + BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); + BOOST_CHECK_TYPE3(tt::common_type::type, boost::ulong_long_type); +#endif + BOOST_CHECK_TYPE3(tt::common_type::type, double); + + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, short); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); +#ifndef BOOST_NO_LONG_LONG + BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); + BOOST_CHECK_TYPE3(tt::common_type::type, boost::ulong_long_type); +#endif + BOOST_CHECK_TYPE3(tt::common_type::type, double); + + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, unsigned short); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); +#ifndef BOOST_NO_LONG_LONG + BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); + BOOST_CHECK_TYPE3(tt::common_type::type, boost::ulong_long_type); +#endif + BOOST_CHECK_TYPE3(tt::common_type::type, double); + + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); +#ifndef BOOST_NO_LONG_LONG + BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); + BOOST_CHECK_TYPE3(tt::common_type::type, boost::ulong_long_type); +#endif + BOOST_CHECK_TYPE3(tt::common_type::type, double); + + BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); + BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); + BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); + BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); + BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); + BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); +#ifndef BOOST_NO_LONG_LONG + BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); + BOOST_CHECK_TYPE3(tt::common_type::type, boost::ulong_long_type); +#endif + BOOST_CHECK_TYPE3(tt::common_type::type, double); + +#ifndef BOOST_NO_LONG_LONG + BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); + BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); + BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); + BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); + BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); + BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); + BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); + BOOST_CHECK_TYPE3(tt::common_type::type, boost::ulong_long_type); + BOOST_CHECK_TYPE3(tt::common_type::type, double); +#endif + BOOST_CHECK_TYPE3(tt::common_type::type, double); + BOOST_CHECK_TYPE3(tt::common_type::type, double); + BOOST_CHECK_TYPE3(tt::common_type::type, double); + BOOST_CHECK_TYPE3(tt::common_type::type, double); + BOOST_CHECK_TYPE3(tt::common_type::type, double); + BOOST_CHECK_TYPE3(tt::common_type::type, double); +#ifndef BOOST_NO_LONG_LONG + BOOST_CHECK_TYPE3(tt::common_type::type, double); + BOOST_CHECK_TYPE3(tt::common_type::type, double); +#endif + BOOST_CHECK_TYPE3(tt::common_type::type, double); + + BOOST_CHECK_TYPE4(tt::common_type::type, double); +#ifndef BOOST_NO_LONG_LONG + BOOST_CHECK_TYPE4(tt::common_type::type, boost::long_long_type); +#endif +} +TT_TEST_END diff --git a/test/tricky_incomplete_type_test.cpp b/test/tricky_incomplete_type_test.cpp new file mode 100644 index 0000000..573b5a6 --- /dev/null +++ b/test/tricky_incomplete_type_test.cpp @@ -0,0 +1,37 @@ + +// (C) Copyright John Maddock 2000. +// 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.boost.org/LICENSE_1_0.txt) + +#include "test.hpp" +#include "check_integral_constant.hpp" +#ifdef TEST_STD +# include +#else +# include +#endif + +TT_TEST_BEGIN(tricky_incomplete_type_test) + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_class::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_compound::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_enum::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_scalar::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_array::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_array::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_array::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_array::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_array::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_array::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_array::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_array::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_function_pointer::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_pointer::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_pointer::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_object_pointer::value, false); + +TT_TEST_END + + diff --git a/test/type_traits_test.cpp b/test/type_traits_test.cpp new file mode 100644 index 0000000..c0fc21d --- /dev/null +++ b/test/type_traits_test.cpp @@ -0,0 +1,103 @@ + +// (C) Copyright John Maddock 2010. +// 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.boost.org/LICENSE_1_0.txt) + +#include + +// +// Just check that each trait actually exists, not +// that it gives the correct answer, we do that elsewhere: +// + +typedef boost::add_const::type t1; +typedef boost::add_cv::type t2; +typedef boost::add_lvalue_reference::type t3; +typedef boost::add_pointer::type t4; +typedef boost::add_reference::type t5; +typedef boost::add_rvalue_reference::type t6; +typedef boost::add_volatile::type t7; + +typedef boost::aligned_storage<2>::type t8; +typedef boost::alignment_of::type t9; +typedef boost::conditional::type t10; +typedef boost::common_type::type t11; +typedef boost::decay::type t12; +typedef boost::extent::type t13; +typedef boost::floating_point_promotion::type t14; +typedef boost::function_traits t15; + +typedef boost::has_new_operator t16; +typedef boost::has_nothrow_assign t17; +typedef boost::has_nothrow_constructor t18; +typedef boost::has_nothrow_copy t19; +typedef boost::has_nothrow_copy_constructor t20; +typedef boost::has_nothrow_default_constructor t21; +typedef boost::has_trivial_assign t22; +typedef boost::has_trivial_constructor t23; +typedef boost::has_trivial_copy t24; +typedef boost::has_trivial_copy_constructor t25; +typedef boost::has_trivial_default_constructor t26; +typedef boost::has_trivial_destructor t27; +typedef boost::has_virtual_destructor t28; + +typedef boost::integral_constant t29; +typedef boost::integral_promotion::type t30; + +typedef boost::is_abstract::type t31; +typedef boost::is_arithmetic::type t32; +typedef boost::is_array::type t33; +typedef boost::is_base_of::type t34; +typedef boost::is_class::type t35; +typedef boost::is_complex::type t36; +typedef boost::is_compound::type t37; +typedef boost::is_const::type t38; +typedef boost::is_convertible::type t39; +typedef boost::is_empty::type t40; +typedef boost::is_enum::type t41; +typedef boost::is_floating_point::type t42; +typedef boost::is_function::type t43; +typedef boost::is_fundamental::type t44; +typedef boost::is_integral::type t45; +typedef boost::is_lvalue_reference::type t46; +typedef boost::is_member_function_pointer::type t47; +typedef boost::is_member_object_pointer::type t48; +typedef boost::is_member_pointer::type t49; +typedef boost::is_object::type t50; +typedef boost::is_pod::type t51; +typedef boost::is_pointer::type t52; +typedef boost::is_polymorphic::type t53; +typedef boost::is_reference::type t54; +typedef boost::is_rvalue_reference::type t55; +typedef boost::is_same::type t56; +typedef boost::is_scalar::type t57; +typedef boost::is_signed::type t58; +typedef boost::is_stateless::type t59; +typedef boost::is_union::type t60; +typedef boost::is_unsigned::type t61; +typedef boost::is_virtual_base_of::type t62; +typedef boost::is_void::type t63; +typedef boost::is_volatile::type t64; +typedef boost::make_signed::type t65; +typedef boost::make_unsigned::type t66; +typedef boost::promote::type t67; +typedef boost::rank::type t68; + +typedef boost::remove_all_extents::type t69; +typedef boost::remove_const::type t70; +typedef boost::remove_cv::type t71; +typedef boost::remove_extent::type t72; +typedef boost::remove_pointer::type t73; +typedef boost::remove_reference::type t74; +typedef boost::remove_volatile::type t75; +typedef boost::type_with_alignment<4>::type t76; + +int main() +{ + return 0; +} + + + +