is_nonnull_default_constructible.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Distributed under the Boost Software License, Version 1.0.
  3. * (See accompanying file LICENSE_1_0.txt or copy at
  4. * https://www.boost.org/LICENSE_1_0.txt)
  5. *
  6. * Copyright (c) 2023 Andrey Semashev
  7. */
  8. /*!
  9. * \file scope/detail/is_nonnull_default_constructible.hpp
  10. *
  11. * This header contains definition of \c is_nonnull_default_constructible
  12. * and \c is_nothrow_nonnull_default_constructible type traits. The type
  13. * traits are useful for preventing default-construction of pointers to
  14. * functions where a default-constructed function object is expected.
  15. * Without it, default- or value-constructing a pointer to function would
  16. * produce a function object that is not callable.
  17. */
  18. #ifndef BOOST_SCOPE_DETAIL_IS_NONNULL_DEFAULT_CONSTRUCTIBLE_HPP_INCLUDED_
  19. #define BOOST_SCOPE_DETAIL_IS_NONNULL_DEFAULT_CONSTRUCTIBLE_HPP_INCLUDED_
  20. #include <type_traits>
  21. #include <boost/scope/detail/config.hpp>
  22. #include <boost/scope/detail/header.hpp>
  23. #ifdef BOOST_HAS_PRAGMA_ONCE
  24. #pragma once
  25. #endif
  26. namespace boost {
  27. namespace scope {
  28. namespace detail {
  29. //! The type trait checks if \c T is not a pointer and is default-constructible
  30. template< typename T >
  31. struct is_nonnull_default_constructible :
  32. public std::is_default_constructible< T >
  33. {
  34. };
  35. template< typename T >
  36. struct is_nonnull_default_constructible< T* > :
  37. public std::false_type
  38. {
  39. };
  40. //! The type trait checks if \c T is not a pointer and is nothrow-default-constructible
  41. template< typename T >
  42. struct is_nothrow_nonnull_default_constructible :
  43. public std::is_nothrow_default_constructible< T >
  44. {
  45. };
  46. template< typename T >
  47. struct is_nothrow_nonnull_default_constructible< T* > :
  48. public std::false_type
  49. {
  50. };
  51. } // namespace detail
  52. } // namespace scope
  53. } // namespace boost
  54. #include <boost/scope/detail/footer.hpp>
  55. #endif // BOOST_SCOPE_DETAIL_IS_NONNULL_DEFAULT_CONSTRUCTIBLE_HPP_INCLUDED_