add_transaction_safe.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. @file add_transaction_safe
  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_TRANSACTION_SAFE_HPP
  8. #define BOOST_CLBL_TRTS_ADD_TRANSACTION_SAFE_HPP
  9. #include <boost/callable_traits/detail/core.hpp>
  10. namespace boost { namespace callable_traits {
  11. BOOST_CLBL_TRTS_DEFINE_SFINAE_ERROR_ORIGIN(add_transaction_safe)
  12. BOOST_CLBL_TRTS_SFINAE_MSG(add_transaction_safe, cannot_add_transaction_safe_to_this_type)
  13. #ifndef BOOST_CLBL_TRTS_ENABLE_TRANSACTION_SAFE
  14. template<typename T>
  15. struct add_transaction_safe_t {
  16. static_assert(std::is_same<T, detail::dummy>::value,
  17. "transaction_safe not supported by this configuration.");
  18. };
  19. template<typename T>
  20. struct add_transaction_safe {
  21. static_assert(std::is_same<T, detail::dummy>::value,
  22. "transaction_safe not supported by this configuration.");
  23. };
  24. #else
  25. //[ add_transaction_safe_hpp
  26. /*`
  27. [section:ref_add_transaction_safe add_transaction_safe]
  28. [heading Header]
  29. ``#include <boost/callable_traits/add_transaction_safe.hpp>``
  30. [heading Definition]
  31. */
  32. template<typename T>
  33. using add_transaction_safe_t = //see below
  34. //<-
  35. detail::try_but_fail_if_invalid<
  36. typename detail::traits<T>::add_transaction_safe,
  37. cannot_add_transaction_safe_to_this_type>;
  38. namespace detail {
  39. template<typename T, typename = std::false_type>
  40. struct add_transaction_safe_impl {};
  41. template<typename T>
  42. struct add_transaction_safe_impl <T, typename std::is_same<
  43. add_transaction_safe_t<T>, detail::dummy>::type>
  44. {
  45. using type = add_transaction_safe_t<T>;
  46. };
  47. }
  48. //->
  49. template<typename T>
  50. struct add_transaction_safe
  51. : detail::add_transaction_safe_impl<T> {};
  52. //<-
  53. #endif // #ifndef BOOST_CLBL_TRTS_ENABLE_TRANSACTION_SAFE
  54. }} // namespace boost::callable_traits
  55. //->
  56. /*`
  57. [heading Constraints]
  58. * `T` must be one of the following:
  59. * function type
  60. * function pointer type
  61. * function reference type
  62. * member function pointer type
  63. * If `T` is a pointer, it may not be cv/ref qualified
  64. [heading Behavior]
  65. * A substitution failure occurs if the constraints are violated.
  66. * Adds the `transaction_safe` specifier to `T`, if not already present.
  67. [heading Input/Output Examples]
  68. [table
  69. [[`T`] [`add_transaction_safe_t<T>`]]
  70. [[`int()`] [`int() transaction_safe`]]
  71. [[`int (&)()`] [`int(&)() transaction_safe`]]
  72. [[`int (*)()`] [`int(*)() transaction_safe`]]
  73. [[`int(foo::*)()`] [`int(foo::*)() transaction_safe`]]
  74. [[`int(foo::*)() &`] [`int(foo::*)() & transaction_safe`]]
  75. [[`int(foo::*)() &&`] [`int(foo::*)() && transaction_safe`]]
  76. [[`int(foo::*)() const`] [`int(foo::*)() const transaction_safe`]]
  77. [[`int(foo::*)() transaction_safe`] [`int(foo::*)() transaction_safe`]]
  78. [[`int`] [(substitution failure)]]
  79. [[`int foo::*`] [(substitution failure)]]
  80. [[`int (*&)()`] [(substitution failure)]]
  81. ]
  82. [heading Example Program]
  83. [import ../example/add_transaction_safe.cpp]
  84. [add_transaction_safe]
  85. [endsect]
  86. */
  87. //]
  88. #endif // #ifndef BOOST_CLBL_TRTS_ADD_TRANSACTION_SAFE_HPP