add C++14 version is_nothrow_destructible

This commit is contained in:
bolero-MURAKAMI 2015-04-03 03:41:00 +09:00
parent d79df43c55
commit 3c2733ad0b
3 changed files with 75 additions and 64 deletions

View file

@ -19,54 +19,6 @@ namespace sprout {
// is_destructible // is_destructible
// //
namespace detail { namespace detail {
struct is_destructible_helper_1 {
public:
template<typename U>
struct w {
U u;
};
template<
typename T,
typename = decltype(std::declval<w<T>&>().~w<T>())
>
static sprout::true_type test(int);
template<typename>
static sprout::false_type test(...);
};
#if defined(_MSC_VER)
template<typename T, typename Base_ = sprout::identity<decltype(sprout::detail::is_destructible_helper_1::test<T>(0))>::type>
struct is_destructible_impl_1
: public Base_
{};
#else
template<typename T>
struct is_destructible_impl_1
: public sprout::identity<decltype(sprout::detail::is_destructible_helper_1::test<T>(0))>::type
{};
#endif
struct is_destructible_helper_2 {
public:
template<
typename T,
typename = decltype(std::declval<T&>().~T())
>
static sprout::true_type test(int);
template<typename>
static sprout::false_type test(...);
};
#if defined(_MSC_VER)
template<typename T, typename Base_ = sprout::identity<decltype(sprout::detail::is_destructible_helper_2::test<T>(0))>::type>
struct is_destructible_impl_2
: public Base_
{};
#else
template<typename T>
struct is_destructible_impl_2
: public sprout::identity<decltype(sprout::detail::is_destructible_helper_2::test<T>(0))>::type
{};
#endif
struct is_destructible_helper { struct is_destructible_helper {
public: public:
template< template<

View file

@ -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 <utility>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/type_traits/integral_constant.hpp>
#include <sprout/type_traits/identity.hpp>
namespace sprout {
//
// is_nothrow_destructible
//
namespace detail {
struct is_nothrow_destructible_helper {
public:
template<typename T>
static sprout::bool_constant<noexcept(std::declval<T&>().~T())> test(int);
template<typename>
static sprout::false_type test(...);
};
#if defined(_MSC_VER)
template<typename T, typename Base_ = sprout::identity<decltype(sprout::detail::is_nothrow_destructible_helper::test<T>(0))>::type>
struct is_nothrow_destructible_impl_0
: public Base_
{};
#else
template<typename T>
struct is_nothrow_destructible_impl_0
: public sprout::identity<decltype(sprout::detail::is_nothrow_destructible_helper::test<T>(0))>::type
{};
#endif
template<
typename T,
bool = std::is_void<T>::value || (std::is_array<T>::value && !std::extent<T>::value) || std::is_function<T>::value,
bool = std::is_reference<T>::value || std::is_scalar<T>::value
>
struct is_nothrow_destructible_impl;
template<typename T>
struct is_nothrow_destructible_impl<T, false, false>
: public sprout::detail::is_nothrow_destructible_impl_0<typename std::remove_all_extents<T>::type>
{};
template<typename T>
struct is_nothrow_destructible_impl<T, true, false>
: public sprout::false_type
{};
template<typename T>
struct is_nothrow_destructible_impl<T, false, true>
: public sprout::true_type
{};
} // namespace detail
template<typename T>
struct is_nothrow_destructible
: public sprout::detail::is_nothrow_destructible_impl<T>
{};
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_TRAITS_IS_NOTHROW_DESTRUCTIBLE_HPP

View file

@ -17,6 +17,7 @@
#include <sprout/type_traits/is_signed.hpp> #include <sprout/type_traits/is_signed.hpp>
#include <sprout/type_traits/is_unsigned.hpp> #include <sprout/type_traits/is_unsigned.hpp>
#include <sprout/type_traits/is_destructible.hpp> #include <sprout/type_traits/is_destructible.hpp>
#include <sprout/type_traits/is_nothrow_destructible.hpp>
#include <sprout/type_traits/result_of.hpp> #include <sprout/type_traits/result_of.hpp>
#include <sprout/type_traits/is_null_pointer.hpp> #include <sprout/type_traits/is_null_pointer.hpp>
#include <sprout/type_traits/detail/type_traits_wrapper.hpp> #include <sprout/type_traits/detail/type_traits_wrapper.hpp>
@ -331,14 +332,16 @@ namespace sprout {
#if SPROUT_CLANG_HAS_FUTURE(has_trivial_destructor) || SPROUT_GCC_OR_LATER(4, 3, 0) #if SPROUT_CLANG_HAS_FUTURE(has_trivial_destructor) || SPROUT_GCC_OR_LATER(4, 3, 0)
template<typename T> template<typename T>
struct is_trivially_destructible struct is_trivially_destructible
: public sprout::bool_constant<__has_trivial_destructor(T)> : public sprout::bool_constant<sprout::is_destructible<T>::value && __has_trivial_destructor(T)>
{}; {};
#else // #if SPROUT_CLANG_HAS_FUTURE(has_trivial_destructor) || SPROUT_GCC_OR_LATER(4, 3, 0) #else // #if SPROUT_CLANG_HAS_FUTURE(has_trivial_destructor) || SPROUT_GCC_OR_LATER(4, 3, 0)
template<typename T> template<typename T>
struct is_trivially_destructible struct is_trivially_destructible
: public sprout::bool_constant< : public sprout::bool_constant<
std::is_scalar<typename std::remove_all_extents<T>::type>::value sprout::is_destructible<T>::value
&& (std::is_scalar<typename std::remove_all_extents<T>::type>::value
|| std::is_reference<typename std::remove_all_extents<T>::type>::value || std::is_reference<typename std::remove_all_extents<T>::type>::value
)
> >
{}; {};
#endif // #if SPROUT_CLANG_HAS_FUTURE(has_trivial_destructor) || SPROUT_GCC_OR_LATER(4, 3, 0) #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 struct is_nothrow_move_assignable
: public sprout::detail::type_traits_wrapper<std::is_nothrow_move_assignable<T> > : public sprout::detail::type_traits_wrapper<std::is_nothrow_move_assignable<T> >
{}; {};
#if !defined(_LIBCPP_VERSION) && SPROUT_GCC_EARLIER(4, 8, 0) // template<typename T>
template<typename T> // struct is_nothrow_destructible
struct is_nothrow_destructible // : public sprout::detail::type_traits_wrapper<std::is_nothrow_destructible<T> >
: public sprout::bool_constant< // {};
std::is_scalar<typename std::remove_all_extents<T>::type>::value
|| std::is_reference<typename std::remove_all_extents<T>::type>::value
>
{};
#else // #if !defined(_LIBCPP_VERSION) && SPROUT_GCC_EARLIER(4, 8, 0)
template<typename T>
struct is_nothrow_destructible
: public sprout::detail::type_traits_wrapper<std::is_nothrow_destructible<T> >
{};
#endif // #if !defined(_LIBCPP_VERSION) && SPROUT_GCC_EARLIER(4, 8, 0)
template<typename T> template<typename T>
struct has_virtual_destructor struct has_virtual_destructor
: public sprout::detail::type_traits_wrapper<std::has_virtual_destructor<T> > : public sprout::detail::type_traits_wrapper<std::has_virtual_destructor<T> >