mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-11-14 10:39:05 +00:00
add C++14 version is_destructible
This commit is contained in:
parent
3bf2a4fc52
commit
1507d435f9
2 changed files with 123 additions and 4 deletions
118
sprout/type_traits/is_destructible.hpp
Normal file
118
sprout/type_traits/is_destructible.hpp
Normal file
|
@ -0,0 +1,118 @@
|
|||
/*=============================================================================
|
||||
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_DESTRUCTIBLE_HPP
|
||||
#define SPROUT_TYPE_TRAITS_IS_DESTRUCTIBLE_HPP
|
||||
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/type_traits/integral_constant.hpp>
|
||||
#include <sprout/type_traits/identity.hpp>
|
||||
#include <sprout/type_traits/detail/type_traits_wrapper.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// is_destructible
|
||||
//
|
||||
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 {
|
||||
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::test<T>(0))>::type>
|
||||
struct is_destructible_impl_0
|
||||
: public Base_
|
||||
{};
|
||||
#else
|
||||
template<typename T>
|
||||
struct is_destructible_impl_0
|
||||
: public sprout::identity<decltype(sprout::detail::is_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),
|
||||
bool = std::is_reference<T>::value || std::is_function<T>::value
|
||||
>
|
||||
struct is_destructible_impl;
|
||||
template<typename T>
|
||||
struct is_destructible_impl<T, false, false>
|
||||
: public sprout::detail::is_destructible_impl_0<typename std::remove_all_extents<T>::type>
|
||||
{};
|
||||
template<typename T>
|
||||
struct is_destructible_impl<T, true, false>
|
||||
: public sprout::false_type
|
||||
{};
|
||||
template<typename T>
|
||||
struct is_destructible_impl<T, false, true>
|
||||
: public sprout::true_type
|
||||
{};
|
||||
} // namespace detail
|
||||
template<typename T>
|
||||
struct is_destructible
|
||||
: public sprout::detail::is_destructible_impl<T>
|
||||
{};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_TYPE_TRAITS_IS_DESTRUCTIBLE_HPP
|
|
@ -17,6 +17,7 @@
|
|||
#include <sprout/type_traits/is_null_pointer.hpp>
|
||||
#include <sprout/type_traits/is_signed.hpp>
|
||||
#include <sprout/type_traits/is_unsigned.hpp>
|
||||
#include <sprout/type_traits/is_destructible.hpp>
|
||||
#include <sprout/type_traits/detail/type_traits_wrapper.hpp>
|
||||
#if !defined(_LIBCPP_VERSION) || (_LIBCPP_VERSION < 1101)
|
||||
# include <sprout/tpp/algorithm/max_element.hpp>
|
||||
|
@ -195,10 +196,10 @@ namespace sprout {
|
|||
struct is_move_assignable
|
||||
: public sprout::detail::type_traits_wrapper<std::is_move_assignable<T> >
|
||||
{};
|
||||
template<typename T>
|
||||
struct is_destructible
|
||||
: public sprout::detail::type_traits_wrapper<std::is_destructible<T> >
|
||||
{};
|
||||
// template<typename T>
|
||||
// struct is_destructible
|
||||
// : public sprout::detail::type_traits_wrapper<std::is_destructible<T> >
|
||||
// {};
|
||||
#if !defined(_LIBCPP_VERSION)
|
||||
#if SPROUT_CLANG_HAS_FUTURE(is_trivially_constructible)
|
||||
template<typename T, typename... Args>
|
||||
|
|
Loading…
Reference in a new issue