diff --git a/include/boost/type_traits/is_copy_constructible.hpp b/include/boost/type_traits/is_copy_constructible.hpp new file mode 100644 index 0000000..106efe8 --- /dev/null +++ b/include/boost/type_traits/is_copy_constructible.hpp @@ -0,0 +1,72 @@ +// (C) Copyright Antony Polukhin 2013. +// +// 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_IS_COPY_CONSTRUCTIBLE_HPP_INCLUDED +#define BOOST_TT_IS_COPY_CONSTRUCTIBLE_HPP_INCLUDED + +#include +#include +#include +#include +#include + +// should be the last #include +#include + +namespace boost { + +namespace detail{ + +template +struct is_copy_constructible_impl2 { +#ifndef BOOST_NO_CXX11_DELETED_FUNCTIONS + template + static boost::type_traits::yes_type test(T1&, boost::mpl::int_()))>* = 0); + static boost::type_traits::no_type test(...); +#else + template + static boost::type_traits::no_type test(T1&, typename T1::boost_move_no_copy_constructor_or_assign* = 0); + static boost::type_traits::yes_type test(...); +#endif + + + BOOST_STATIC_CONSTANT(bool, + value = (sizeof(test(boost::declval())) == sizeof(boost::type_traits::yes_type)) + ); +}; + +template +struct is_copy_constructible_impl2 { + BOOST_STATIC_CONSTANT(bool, value = false); +}; + +template +struct is_copy_constructible_impl { + + BOOST_STATIC_CONSTANT(bool, value = ( + boost::detail::is_copy_constructible_impl2< + boost::is_base_and_derived::value, + T>::value + )); +}; + +} // namespace detail + +BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_copy_constructible,T,::boost::detail::is_copy_constructible_impl::value) +BOOST_TT_AUX_BOOL_TRAIT_SPEC1(is_copy_constructible,void,false) +#ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS +BOOST_TT_AUX_BOOL_TRAIT_SPEC1(is_copy_constructible,void const,false) +BOOST_TT_AUX_BOOL_TRAIT_SPEC1(is_copy_constructible,void const volatile,false) +BOOST_TT_AUX_BOOL_TRAIT_SPEC1(is_copy_constructible,void volatile,false) +#endif + +} // namespace boost + +#include + +#endif // BOOST_TT_IS_COPY_CONSTRUCTIBLE_HPP_INCLUDED diff --git a/test/is_copy_constructible_test.cpp b/test/is_copy_constructible_test.cpp new file mode 100644 index 0000000..d05988f --- /dev/null +++ b/test/is_copy_constructible_test.cpp @@ -0,0 +1,285 @@ +// (C) Copyright John Maddock 2000. +// (C) Copyright Antony Polukhin 2013. +// 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 + +#include + +struct has { + has(){} + has(const has&){} +}; + +struct has2 { + const int& i; +}; + +struct has3 { + has3(has3&){} +}; + + +struct has4 { // Copy constructor must be generated by compiler + has4(has4*){} +}; + +struct has_not: public boost::noncopyable { + has_not() {} +}; + +#ifndef BOOST_NO_CXX11_DELETED_FUNCTIONS + +struct has_not2 { + has_not2() {} + has_not2(has_not2&) = delete; +}; + +struct has_not3 { + has_not3() {} + has_not3(const has_not3&) = delete; +}; + +#endif // BOOST_NO_CXX11_DELETED_FUNCTIONS + +struct has_not4: private boost::noncopyable { + has_not4() {} +private: + has_not4(const has_not4&); +}; + +struct has_not5 { +private: + BOOST_MOVABLE_BUT_NOT_COPYABLE(has_not5) +}; + + +TT_TEST_BEGIN(is_copy_constructible) + +// Main part of the test +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, false); +#ifndef BOOST_NO_CXX11_DELETED_FUNCTIONS +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, false); +#endif +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, false); + +// Requires some basic support from Boost.Move in C++03 +#ifndef BOOST_NO_CXX11_DELETED_FUNCTIONS // TODO: remove when Boost.Move will be patched +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, false); +#endif + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +#ifndef TEST_STD +// unspecified behaviour: +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +#endif + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +#ifndef TEST_STD +// unspecified behaviour: +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +#endif +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +#ifndef TEST_STD +// unspecified behaviour: +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +#endif + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +#ifndef TEST_STD +// unspecified behaviour: +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +#endif + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +#ifndef TEST_STD +// unspecified behaviour: +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +#endif + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +#ifndef TEST_STD +// unspecified behaviour: +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +#endif + +#ifdef BOOST_HAS_LONG_LONG + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible< ::boost::ulong_long_type>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible< ::boost::long_long_type>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible< ::boost::ulong_long_type const>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible< ::boost::long_long_type const>::value, true); +#ifndef TEST_STD +// unspecified behaviour: +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible< ::boost::ulong_long_type volatile>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible< ::boost::long_long_type volatile>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible< ::boost::ulong_long_type const volatile>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible< ::boost::long_long_type const volatile>::value, true); +#endif +#endif + +#ifdef BOOST_HAS_MS_INT64 + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible<__int8>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible<__int8 const>::value, true); +#ifndef TEST_STD +// unspecified behaviour: +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible<__int8 volatile>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible<__int8 const volatile>::value, true); +#endif + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible<__int16>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible<__int16 const>::value, true); +#ifndef TEST_STD +// unspecified behaviour: +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible<__int16 volatile>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible<__int16 const volatile>::value, true); +#endif + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible<__int32>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible<__int32 const>::value, true); +#ifndef TEST_STD +// unspecified behaviour: +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible<__int32 volatile>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible<__int32 const volatile>::value, true); +#endif + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible<__int64>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible<__int64 const>::value, true); +#ifndef TEST_STD +// unspecified behaviour: +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible<__int64 volatile>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible<__int64 const volatile>::value, true); +#endif +#endif + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +#ifndef TEST_STD +// unspecified behaviour: +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +#endif + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +#ifndef TEST_STD +// unspecified behaviour: +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +#endif + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +#ifndef TEST_STD +// unspecified behaviour: +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +#endif + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +#endif +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); + +// Following three tests may give different results because of copiler and C++03/C++11 +BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, false, true); +BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, false, true); +BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, false, true); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, false); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); + +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_NOEXCEPT) +// Copy constructor of nothrow_move_UDT is implicitly deleted because of user declared move constructor. +// Hovewer not all compilers implement that feature correctly. +BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, false, true); +#endif + +//TODO: What do we need to do in this situation? +//BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_copy_constructible::value, true); + + +TT_TEST_END + + +