add_noexcept.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. @file add_noexcept
  3. @Copyright Barrett Adair 2015-2017
  4. Distributed under the Boost Software License, Version 1.0.
  5. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  6. */
  7. #ifndef BOOST_CLBL_TRTS_ADD_NOEXCEPT_HPP
  8. #define BOOST_CLBL_TRTS_ADD_NOEXCEPT_HPP
  9. #include <boost/callable_traits/detail/core.hpp>
  10. namespace boost { namespace callable_traits {
  11. BOOST_CLBL_TRTS_DEFINE_SFINAE_ERROR_ORIGIN(add_noexcept)
  12. BOOST_CLBL_TRTS_SFINAE_MSG(add_noexcept, cannot_add_noexcept_to_this_type)
  13. #ifndef BOOST_CLBL_TRTS_ENABLE_NOEXCEPT_TYPES
  14. template<typename T>
  15. struct add_noexcept_t {
  16. static_assert(std::is_same<T, detail::dummy>::value,
  17. "noexcept types not supported by this configuration.");
  18. };
  19. template<typename T>
  20. struct add_noexcept {
  21. static_assert(std::is_same<T, detail::dummy>::value,
  22. "noexcept types not supported by this configuration.");
  23. };
  24. #else
  25. //[ add_noexcept_hpp
  26. /*`
  27. [section:ref_add_noexcept add_noexcept]
  28. [heading Header]
  29. ``#include <boost/callable_traits/add_noexcept.hpp>``
  30. [heading Definition]
  31. */
  32. template<typename T>
  33. using add_noexcept_t = //see below
  34. //<-
  35. detail::try_but_fail_if_invalid<
  36. typename detail::traits<T>::add_noexcept,
  37. cannot_add_noexcept_to_this_type>;
  38. namespace detail {
  39. template<typename T, typename = std::false_type>
  40. struct add_noexcept_impl {};
  41. template<typename T>
  42. struct add_noexcept_impl <T, typename std::is_same<
  43. add_noexcept_t<T>, detail::dummy>::type>
  44. {
  45. using type = add_noexcept_t<T>;
  46. };
  47. }
  48. //->
  49. template<typename T>
  50. struct add_noexcept : detail::add_noexcept_impl<T> {};
  51. //<-
  52. #endif // #ifdef BOOST_CLBL_TRTS_ENABLE_NOEXCEPT_TYPES
  53. }} // namespace boost::callable_traits
  54. //->
  55. /*`
  56. [heading Constraints]
  57. * `T` must be one of the following:
  58. * function type
  59. * function pointer type
  60. * function reference type
  61. * member function pointer type
  62. * If `T` is a pointer, it may not be cv/ref qualified
  63. [heading Behavior]
  64. * A substitution failure occurs if the constraints are violated.
  65. * Adds a `noexcept` specifier to `T`, if not already present.
  66. [heading Input/Output Examples]
  67. [table
  68. [[`T`] [`add_noexcept_t<T>`]]
  69. [[`int()`] [`int() noexcept`]]
  70. [[`int (&)()`] [`int(&)() noexcept`]]
  71. [[`int (*)()`] [`int(*)() noexcept`]]
  72. [[`int(foo::*)()`] [`int(foo::*)() noexcept`]]
  73. [[`int(foo::*)() &`] [`int(foo::*)() & noexcept`]]
  74. [[`int(foo::*)() &&`] [`int(foo::*)() && noexcept`]]
  75. [[`int(foo::*)() const transaction_safe`] [`int(foo::*)() const transaction_safe noexcept`]]
  76. [[`int(foo::*)() noexcept`] [`int(foo::*)() noexcept`]]
  77. [[`int`] [(substitution failure)]]
  78. [[`int foo::*`] [(substitution failure)]]
  79. [[`int (*&)()`] [(substitution failure)]]
  80. ]
  81. [heading Example Program]
  82. [import ../example/add_noexcept.cpp]
  83. [add_noexcept]
  84. [endsect]
  85. */
  86. //]
  87. #endif // #ifndef BOOST_CLBL_TRTS_ADD_NOEXCEPT_HPP