diff --git a/include/boost/type_traits/is_copy_assignable.hpp b/include/boost/type_traits/is_copy_assignable.hpp index 76afdda..ed04927 100644 --- a/include/boost/type_traits/is_copy_assignable.hpp +++ b/include/boost/type_traits/is_copy_assignable.hpp @@ -11,8 +11,7 @@ #include #include -#include -#include +#include #if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) && !defined(BOOST_NO_CXX11_DECLTYPE) \ && !defined(BOOST_INTEL_CXX_VERSION) && \ @@ -112,7 +111,7 @@ struct is_copy_assignable_impl { typedef BOOST_DEDUCED_TYPENAME boost::remove_reference::type unreferenced_t; BOOST_STATIC_CONSTANT(bool, value = ( boost::detail::is_copy_assignable_impl2< - boost::is_base_and_derived::value + boost::is_noncopyable::value || boost::is_const::value || boost::is_array::value ,T >::value @@ -120,7 +119,7 @@ struct is_copy_assignable_impl { #else BOOST_STATIC_CONSTANT(bool, value = ( boost::detail::is_copy_assignable_impl2< - boost::is_base_and_derived::value,T + boost::is_noncopyable::value,T >::value )); #endif diff --git a/include/boost/type_traits/is_copy_constructible.hpp b/include/boost/type_traits/is_copy_constructible.hpp index c688264..ef97e18 100644 --- a/include/boost/type_traits/is_copy_constructible.hpp +++ b/include/boost/type_traits/is_copy_constructible.hpp @@ -37,8 +37,7 @@ template <> struct is_copy_constructible : public false_type{}; // an incorrect value, which just defers the issue into the users code) as well. We can at least fix // boost::non_copyable as a base class as a special case: // -#include -#include +#include namespace boost { @@ -50,7 +49,7 @@ namespace boost { } - template struct is_copy_constructible : public detail::is_copy_constructible_imp::value>{}; + template struct is_copy_constructible : public detail::is_copy_constructible_imp::value>{}; template <> struct is_copy_constructible : public false_type{}; template <> struct is_copy_constructible : public false_type{}; @@ -64,13 +63,12 @@ namespace boost { #else #include -#include +#include #include #include #include #include #include -#include #ifdef BOOST_MSVC #pragma warning(push) @@ -160,7 +158,7 @@ namespace boost { BOOST_STATIC_CONSTANT(bool, value = ( boost::detail::is_copy_constructible_impl2< - boost::is_base_and_derived::value, + boost::is_noncopyable::value, T >::value )); diff --git a/include/boost/type_traits/is_noncopyable.hpp b/include/boost/type_traits/is_noncopyable.hpp new file mode 100644 index 0000000..787103e --- /dev/null +++ b/include/boost/type_traits/is_noncopyable.hpp @@ -0,0 +1,39 @@ +#ifndef BOOST_TYPE_TRAITS_IS_NONCOPYABLE_HPP_INCLUDED +#define BOOST_TYPE_TRAITS_IS_NONCOPYABLE_HPP_INCLUDED + +// +// Copyright 2018 Peter Dimov +// +// 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 +// +// is_noncopyable returns whether T is derived from boost::noncopyable +// + +#include + +namespace boost +{ + +#ifndef BOOST_NONCOPYABLE_BASE_TOKEN_DEFINED +#define BOOST_NONCOPYABLE_BASE_TOKEN_DEFINED + +// boost::noncopyable derives from noncopyable_::base_token to enable us +// to recognize it. The definition is macro-guarded so that we can replicate +// it here without including boost/core/noncopyable.hpp, which is in Core. + +namespace noncopyable_ +{ + struct base_token {}; +} + +#endif // #ifndef BOOST_NONCOPYABLE_BASE_TOKEN_DEFINED + +template struct is_noncopyable: is_base_and_derived +{ +}; + +} // namespace boost + +#endif // #ifndef BOOST_TYPE_TRAITS_IS_NONCOPYABLE_HPP_INCLUDED diff --git a/test/is_noncopyable_test.cpp b/test/is_noncopyable_test.cpp new file mode 100644 index 0000000..57d41d5 --- /dev/null +++ b/test/is_noncopyable_test.cpp @@ -0,0 +1,46 @@ + +// (C) Copyright John Maddock 2000. +// (C) Copyright Peter Dimov 2018. +// 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) + +#ifdef TEST_STD +# include +#else +# include +#endif +#include +#include "test.hpp" +#include "check_integral_constant.hpp" + +struct X +{ +}; + +class Y: private boost::noncopyable +{ +}; + +class Z: private Y +{ +}; + +TT_TEST_BEGIN(is_noncopyable) + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_noncopyable::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_noncopyable::value, false); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_noncopyable::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_noncopyable::value, false); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_noncopyable::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_noncopyable::value, false); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_noncopyable::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_noncopyable::value, true); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_noncopyable::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_noncopyable::value, true); + +TT_TEST_END