is_destructible.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // (C) Copyright John Maddock 2015.
  2. // Use, modification and distribution are subject to the Boost Software License,
  3. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt).
  5. //
  6. // See http://www.boost.org/libs/type_traits for most recent version including documentation.
  7. #ifndef BOOST_TT_IS_DESTRUCTIBLE_HPP_INCLUDED
  8. #define BOOST_TT_IS_DESTRUCTIBLE_HPP_INCLUDED
  9. #include <cstddef> // size_t
  10. #include <boost/type_traits/integral_constant.hpp>
  11. #include <boost/detail/workaround.hpp>
  12. #include <boost/type_traits/is_complete.hpp>
  13. #include <boost/static_assert.hpp>
  14. #if !defined(BOOST_NO_CXX11_DECLTYPE) && !BOOST_WORKAROUND(BOOST_MSVC, < 1800)
  15. #include <boost/type_traits/detail/yes_no_type.hpp>
  16. #include <boost/type_traits/declval.hpp>
  17. namespace boost{
  18. namespace detail{
  19. struct is_destructible_imp
  20. {
  21. template<typename T, typename = decltype(boost::declval<T&>().~T())>
  22. static boost::type_traits::yes_type test(int);
  23. template<typename>
  24. static boost::type_traits::no_type test(...);
  25. };
  26. }
  27. template <class T> struct is_destructible : public integral_constant<bool, sizeof(boost::detail::is_destructible_imp::test<T>(0)) == sizeof(boost::type_traits::yes_type)>
  28. {
  29. BOOST_STATIC_ASSERT_MSG(boost::is_complete<T>::value, "Arguments to is_destructible must be complete types");
  30. };
  31. #else
  32. #include <boost/type_traits/is_pod.hpp>
  33. #include <boost/type_traits/is_class.hpp>
  34. namespace boost{
  35. // We don't know how to implement this:
  36. template <class T> struct is_destructible : public integral_constant<bool, is_pod<T>::value || is_class<T>::value>
  37. {
  38. BOOST_STATIC_ASSERT_MSG(boost::is_complete<T>::value, "Arguments to is_destructible must be complete types");
  39. };
  40. #endif
  41. template <> struct is_destructible<void> : public false_type{};
  42. template <> struct is_destructible<void const> : public false_type{};
  43. template <> struct is_destructible<void volatile> : public false_type{};
  44. template <> struct is_destructible<void const volatile> : public false_type{};
  45. template <class T> struct is_destructible<T&> : public is_destructible<T>{};
  46. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  47. template <class T> struct is_destructible<T&&> : public is_destructible<T>{};
  48. #endif
  49. template <class T, std::size_t N> struct is_destructible<T[N]> : public is_destructible<T>{};
  50. template <class T> struct is_destructible<T[]> : public is_destructible<T>{};
  51. } // namespace boost
  52. #endif // BOOST_TT_IS_DESTRUCTIBLE_HPP_INCLUDED