Merge pull request #88 from boostorg/feature/is_noncopyable

Do not include boost/noncopyable.hpp to avoid a dependency on Core
This commit is contained in:
jzmaddock
2018-08-27 18:09:12 +01:00
committed by GitHub
4 changed files with 92 additions and 10 deletions

View File

@ -11,8 +11,7 @@
#include <boost/config.hpp>
#include <boost/type_traits/detail/yes_no_type.hpp>
#include <boost/type_traits/is_base_and_derived.hpp>
#include <boost/noncopyable.hpp>
#include <boost/type_traits/is_noncopyable.hpp>
#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<T>::type unreferenced_t;
BOOST_STATIC_CONSTANT(bool, value = (
boost::detail::is_copy_assignable_impl2<
boost::is_base_and_derived<boost::noncopyable, T>::value
boost::is_noncopyable<T>::value
|| boost::is_const<unreferenced_t>::value || boost::is_array<unreferenced_t>::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<boost::noncopyable, T>::value,T
boost::is_noncopyable<T>::value,T
>::value
));
#endif

View File

@ -37,8 +37,7 @@ template <> struct is_copy_constructible<void volatile> : 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 <boost/type_traits/is_base_and_derived.hpp>
#include <boost/noncopyable.hpp>
#include <boost/type_traits/is_noncopyable.hpp>
namespace boost {
@ -50,7 +49,7 @@ namespace boost {
}
template <class T> struct is_copy_constructible : public detail::is_copy_constructible_imp<T, is_base_and_derived<boost::noncopyable, T>::value>{};
template <class T> struct is_copy_constructible : public detail::is_copy_constructible_imp<T, is_noncopyable<T>::value>{};
template <> struct is_copy_constructible<void> : public false_type{};
template <> struct is_copy_constructible<void const> : public false_type{};
@ -64,13 +63,12 @@ namespace boost {
#else
#include <boost/type_traits/detail/yes_no_type.hpp>
#include <boost/type_traits/is_base_and_derived.hpp>
#include <boost/type_traits/is_noncopyable.hpp>
#include <boost/type_traits/add_reference.hpp>
#include <boost/type_traits/is_rvalue_reference.hpp>
#include <boost/type_traits/declval.hpp>
#include <boost/type_traits/is_array.hpp>
#include <boost/type_traits/declval.hpp>
#include <boost/noncopyable.hpp>
#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<boost::noncopyable, T>::value,
boost::is_noncopyable<T>::value,
T
>::value
));

View File

@ -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<T> returns whether T is derived from boost::noncopyable
//
#include <boost/type_traits/is_base_and_derived.hpp>
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<class T> struct is_noncopyable: is_base_and_derived<noncopyable_::base_token, T>
{
};
} // namespace boost
#endif // #ifndef BOOST_TYPE_TRAITS_IS_NONCOPYABLE_HPP_INCLUDED

View File

@ -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 <type_traits>
#else
# include <boost/type_traits/is_noncopyable.hpp>
#endif
#include <boost/core/noncopyable.hpp>
#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<void>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_noncopyable<const void>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_noncopyable<int>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_noncopyable<const int>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_noncopyable<X>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_noncopyable<const X>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_noncopyable<Y>::value, true);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_noncopyable<const Y>::value, true);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_noncopyable<Z>::value, true);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_noncopyable<const Z>::value, true);
TT_TEST_END