From 3c2733ad0b52e0b8e3bbc6456804041601b59b50 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Fri, 3 Apr 2015 03:41:00 +0900 Subject: [PATCH] add C++14 version is_nothrow_destructible --- sprout/type_traits/is_destructible.hpp | 48 -------------- .../type_traits/is_nothrow_destructible.hpp | 66 +++++++++++++++++++ sprout/type_traits/std_type_traits.hpp | 25 +++---- 3 files changed, 75 insertions(+), 64 deletions(-) create mode 100644 sprout/type_traits/is_nothrow_destructible.hpp diff --git a/sprout/type_traits/is_destructible.hpp b/sprout/type_traits/is_destructible.hpp index 0fc04276..a5127bfc 100644 --- a/sprout/type_traits/is_destructible.hpp +++ b/sprout/type_traits/is_destructible.hpp @@ -19,54 +19,6 @@ namespace sprout { // is_destructible // namespace detail { - struct is_destructible_helper_1 { - public: - template - struct w { - U u; - }; - template< - typename T, - typename = decltype(std::declval&>().~w()) - > - static sprout::true_type test(int); - template - static sprout::false_type test(...); - }; -#if defined(_MSC_VER) - template(0))>::type> - struct is_destructible_impl_1 - : public Base_ - {}; -#else - template - struct is_destructible_impl_1 - : public sprout::identity(0))>::type - {}; -#endif - - struct is_destructible_helper_2 { - public: - template< - typename T, - typename = decltype(std::declval().~T()) - > - static sprout::true_type test(int); - template - static sprout::false_type test(...); - }; -#if defined(_MSC_VER) - template(0))>::type> - struct is_destructible_impl_2 - : public Base_ - {}; -#else - template - struct is_destructible_impl_2 - : public sprout::identity(0))>::type - {}; -#endif - struct is_destructible_helper { public: template< diff --git a/sprout/type_traits/is_nothrow_destructible.hpp b/sprout/type_traits/is_nothrow_destructible.hpp new file mode 100644 index 00000000..92fed755 --- /dev/null +++ b/sprout/type_traits/is_nothrow_destructible.hpp @@ -0,0 +1,66 @@ +/*============================================================================= + Copyright (c) 2011-2015 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + 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 SPROUT_TYPE_TRAITS_IS_NOTHROW_DESTRUCTIBLE_HPP +#define SPROUT_TYPE_TRAITS_IS_NOTHROW_DESTRUCTIBLE_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + // + // is_nothrow_destructible + // + namespace detail { + struct is_nothrow_destructible_helper { + public: + template + static sprout::bool_constant().~T())> test(int); + template + static sprout::false_type test(...); + }; +#if defined(_MSC_VER) + template(0))>::type> + struct is_nothrow_destructible_impl_0 + : public Base_ + {}; +#else + template + struct is_nothrow_destructible_impl_0 + : public sprout::identity(0))>::type + {}; +#endif + + template< + typename T, + bool = std::is_void::value || (std::is_array::value && !std::extent::value) || std::is_function::value, + bool = std::is_reference::value || std::is_scalar::value + > + struct is_nothrow_destructible_impl; + template + struct is_nothrow_destructible_impl + : public sprout::detail::is_nothrow_destructible_impl_0::type> + {}; + template + struct is_nothrow_destructible_impl + : public sprout::false_type + {}; + template + struct is_nothrow_destructible_impl + : public sprout::true_type + {}; + } // namespace detail + template + struct is_nothrow_destructible + : public sprout::detail::is_nothrow_destructible_impl + {}; +} // namespace sprout + +#endif // #ifndef SPROUT_TYPE_TRAITS_IS_NOTHROW_DESTRUCTIBLE_HPP diff --git a/sprout/type_traits/std_type_traits.hpp b/sprout/type_traits/std_type_traits.hpp index 42964349..62796e6a 100644 --- a/sprout/type_traits/std_type_traits.hpp +++ b/sprout/type_traits/std_type_traits.hpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -331,14 +332,16 @@ namespace sprout { #if SPROUT_CLANG_HAS_FUTURE(has_trivial_destructor) || SPROUT_GCC_OR_LATER(4, 3, 0) template struct is_trivially_destructible - : public sprout::bool_constant<__has_trivial_destructor(T)> + : public sprout::bool_constant::value && __has_trivial_destructor(T)> {}; #else // #if SPROUT_CLANG_HAS_FUTURE(has_trivial_destructor) || SPROUT_GCC_OR_LATER(4, 3, 0) template struct is_trivially_destructible : public sprout::bool_constant< - std::is_scalar::type>::value + sprout::is_destructible::value + && (std::is_scalar::type>::value || std::is_reference::type>::value + ) > {}; #endif // #if SPROUT_CLANG_HAS_FUTURE(has_trivial_destructor) || SPROUT_GCC_OR_LATER(4, 3, 0) @@ -376,20 +379,10 @@ namespace sprout { struct is_nothrow_move_assignable : public sprout::detail::type_traits_wrapper > {}; -#if !defined(_LIBCPP_VERSION) && SPROUT_GCC_EARLIER(4, 8, 0) - template - struct is_nothrow_destructible - : public sprout::bool_constant< - std::is_scalar::type>::value - || std::is_reference::type>::value - > - {}; -#else // #if !defined(_LIBCPP_VERSION) && SPROUT_GCC_EARLIER(4, 8, 0) - template - struct is_nothrow_destructible - : public sprout::detail::type_traits_wrapper > - {}; -#endif // #if !defined(_LIBCPP_VERSION) && SPROUT_GCC_EARLIER(4, 8, 0) +// template +// struct is_nothrow_destructible +// : public sprout::detail::type_traits_wrapper > +// {}; template struct has_virtual_destructor : public sprout::detail::type_traits_wrapper >