1 /* 2 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 */ 8 9 #ifndef BOOST_CLBL_TRTS_APPLY_RETURN_HPP 10 #define BOOST_CLBL_TRTS_APPLY_RETURN_HPP 11 12 #include <boost/callable_traits/detail/core.hpp> 13 14 namespace boost { namespace callable_traits { 15 16 BOOST_CLBL_TRTS_DEFINE_SFINAE_ERROR_ORIGIN(apply_return) 17 BOOST_CLBL_TRTS_SFINAE_MSG(apply_return, invalid_types_for_apply_return) 18 19 namespace detail { 20 21 template<typename T, typename R> 22 struct apply_return_helper { 23 using type = typename detail::traits<T>::template apply_return<R>; 24 }; 25 26 //special case 27 template<typename... Args, typename R> 28 struct apply_return_helper<std::tuple<Args...>, R> { 29 using type = R(Args...); 30 }; 31 } 32 33 //[ apply_return_hpp 34 /*` 35 [section:ref_apply_return apply_return] 36 [heading Header] 37 ``#include <boost/callable_traits/apply_return.hpp>`` 38 [heading Definition] 39 */ 40 41 template<typename T, typename R> 42 using apply_return_t = //see below 43 //<- 44 detail::try_but_fail_if_invalid< 45 typename detail::apply_return_helper<T, R>::type, 46 invalid_types_for_apply_return>; 47 48 namespace detail { 49 50 template<typename T, typename R, typename = std::false_type> 51 struct apply_return_impl {}; 52 53 template<typename T, typename R> 54 struct apply_return_impl <T, R, typename std::is_same< 55 apply_return_t<T, R>, detail::dummy>::type> 56 { 57 using type = apply_return_t<T, R>; 58 }; 59 } 60 //-> 61 62 template<typename T, typename R> 63 struct apply_return : detail::apply_return_impl<T, R> {}; 64 65 //<- 66 }} // namespace boost::callable_traits 67 //-> 68 69 /*` 70 [heading Constraints] 71 * `T` must one of the following: 72 * `std::tuple` template instantiation 73 * function 74 * function pointer 75 * function reference 76 * member function pointer 77 * member data pointer 78 * If `T` is a pointer, it may not be cv/ref qualified 79 80 [heading Behavior] 81 * When `T` is `std::tuple<Args...>`, the aliased type is `R(Args...)`. 82 * When `T` is a function, function pointer, function reference, or member function pointer, the aliased type's return type is `R`, but is otherwise identical to `T`. 83 * When `T` is a member data pointer of class `foo` to a `U` type (such that `T` is `U foo::*`), the aliased type is `R foo::*`. 84 85 [heading Input/Output Examples] 86 [table 87 [[`T`] [`apply_return_t<T, float>`]] 88 [[`std::tuple<int, int>`] [`float(int, int)`]] 89 [[`int()`] [`float()`]] 90 [[`int (&)()`] [`float(&)()`]] 91 [[`int (*)()`] [`float(*)()`]] 92 [[`int (*)(...)`] [`float(*)()`]] 93 [[`int(foo::*)()`] [`float(foo::*)()`]] 94 [[`int(foo::*)() &`] [`float(foo::*)() &`]] 95 [[`int(foo::*)() &&`] [`float(foo::*)() &&`]] 96 [[`int(foo::*)() const`] [`float(foo::*)() const`]] 97 [[`int(foo::*)() transaction_safe`] [`float(foo::*)() transaction_safe`]] 98 [[`int foo::*`] [`float foo::*`]] 99 [[`int`] [(substitution failure)]] 100 [[`int (*const)()`] [(substitution failure)]] 101 ] 102 103 [heading Example Program] 104 [/import ../example/apply_return.cpp] 105 [apply_return] 106 [endsect] 107 */ 108 //] 109 #endif 110