From 434e26e7a3fe223aeae686032edb230b85daba33 Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Thu, 11 Jun 2015 10:00:31 +0100 Subject: [PATCH] Improve is_destructible and add tests. --- include/boost/type_traits/is_destructible.hpp | 7 + test/is_destructible_test.cpp | 177 ++++++++++++++++++ 2 files changed, 184 insertions(+) create mode 100644 test/is_destructible_test.cpp diff --git a/include/boost/type_traits/is_destructible.hpp b/include/boost/type_traits/is_destructible.hpp index fe421d9..7f266a9 100644 --- a/include/boost/type_traits/is_destructible.hpp +++ b/include/boost/type_traits/is_destructible.hpp @@ -32,6 +32,8 @@ namespace boost{ } template struct is_destructible : public integral_constant(0)) == sizeof(boost::type_traits::yes_type)>{}; + template struct is_destructible : public is_destructible{}; + template struct is_destructible : public is_destructible{}; #else @@ -44,6 +46,11 @@ namespace boost{ template struct is_destructible : public integral_constant::value || is_class::value>{}; #endif + template <> struct is_destructible : public false_type{}; + template <> struct is_destructible : public false_type{}; + template <> struct is_destructible : public false_type{}; + template <> struct is_destructible : public false_type{}; + } // namespace boost #endif // BOOST_TT_IS_DESTRUCTIBLE_HPP_INCLUDED diff --git a/test/is_destructible_test.cpp b/test/is_destructible_test.cpp new file mode 100644 index 0000000..a4f58ba --- /dev/null +++ b/test/is_destructible_test.cpp @@ -0,0 +1,177 @@ + +// (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 + +#if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) + +struct deleted_destruct +{ + deleted_destruct(); + ~deleted_destruct() = delete; +}; + +#endif + + +TT_TEST_BEGIN(is_destructible) + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); + +#ifdef BOOST_HAS_LONG_LONG + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible< ::boost::ulong_long_type>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible< ::boost::long_long_type>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible< ::boost::ulong_long_type const>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible< ::boost::long_long_type const>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible< ::boost::ulong_long_type volatile>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible< ::boost::long_long_type volatile>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible< ::boost::ulong_long_type const volatile>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible< ::boost::long_long_type const volatile>::value, true); + +#endif + +#ifdef BOOST_HAS_MS_INT64 + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible<__int8>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible<__int8 const>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible<__int8 volatile>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible<__int8 const volatile>::value, true); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible<__int16>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible<__int16 const>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible<__int16 volatile>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible<__int16 const volatile>::value, true); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible<__int32>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible<__int32 const>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible<__int32 volatile>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible<__int32 const volatile>::value, true); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible<__int64>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible<__int64 const>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible<__int64 volatile>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible<__int64 const volatile>::value, true); + +#endif + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); + + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); + +// +// These are commented out for now because it's not clear what the semantics should be: +// on the one hand references always have trivial destructors (in the sense that there is +// nothing to destruct), on the other hand the thing referenced may not have a trivial +// destructor, it really depends upon the users code as to what should happen here: +// +//BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, false); +//BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, false); + +#ifndef BOOST_NO_CXX11_DELETED_FUNCTIONS +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_destructible::value, false); +#endif + +TT_TEST_END + + +