Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:45

0001 /*
0002 
0003 @Copyright Barrett Adair 2015-2017
0004 Distributed under the Boost Software License, Version 1.0.
0005 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
0006 
0007 */
0008 
0009 #ifndef BOOST_CLBL_TRTS_APPLY_MEMBER_POINTER_HPP
0010 #define BOOST_CLBL_TRTS_APPLY_MEMBER_POINTER_HPP
0011 
0012 #include <boost/callable_traits/detail/core.hpp>
0013 
0014 namespace boost { namespace callable_traits {
0015 
0016 BOOST_CLBL_TRTS_DEFINE_SFINAE_ERROR_ORIGIN(apply_member_pointer)
0017 BOOST_CLBL_TRTS_SFINAE_MSG(apply_member_pointer, members_cannot_have_a_type_of_void)
0018 BOOST_CLBL_TRTS_SFINAE_MSG(apply_member_pointer, second_template_argument_must_be_a_class_or_struct)
0019 
0020 namespace detail {
0021 
0022     template<typename T, typename C, bool = std::is_class<C>::value>
0023     struct make_member_pointer;
0024 
0025     template<typename T, typename C>
0026     struct make_member_pointer<T, C, true> {
0027         using type = typename std::remove_reference<T>::type C::*;
0028     };
0029 
0030     template<typename C>
0031     struct make_member_pointer<void, C, true> {
0032         using type = invalid_type;
0033     };
0034 
0035     template<typename T, typename C>
0036     struct make_member_pointer<T, C, false> {
0037         using type = error_type<T>;
0038     };
0039 
0040     template<typename T, typename C>
0041     using make_member_pointer_t = typename make_member_pointer<T, C>::type;
0042 }
0043 
0044 //[ apply_member_pointer_hpp
0045 /*`
0046 [section:ref_apply_member_pointer apply_member_pointer]
0047 [heading Header]
0048 ``#include <boost/callable_traits/apply_member_pointer.hpp>``
0049 [heading Definition]
0050 */
0051 
0052 template<typename T, typename C>
0053 using apply_member_pointer_t = //see below
0054 //<-
0055     detail::sfinae_try<
0056         detail::fallback_if_invalid<
0057             typename detail::traits<T>::template apply_member_pointer<C>,
0058             typename detail::make_member_pointer<T, C>::type>,
0059 
0060         detail::fail_when_same<void, T, members_cannot_have_a_type_of_void>,
0061 
0062         detail::fail_if<!std::is_class<C>::value,
0063             second_template_argument_must_be_a_class_or_struct> >;
0064 
0065 namespace detail {
0066 
0067     template<typename T, typename C, typename = std::false_type>
0068     struct apply_member_pointer_impl {};
0069 
0070     template<typename T, typename C>
0071     struct apply_member_pointer_impl <T, C, typename std::is_same<
0072         apply_member_pointer_t<T, C>, detail::dummy>::type>
0073     {
0074         using type = apply_member_pointer_t<T, C>;
0075     };
0076 }
0077 
0078 //->
0079 
0080 template<typename T, typename C>
0081 struct apply_member_pointer : detail::apply_member_pointer_impl<T, C> {};
0082 
0083 //<-
0084 }} // namespace boost::callable_traits
0085 //->
0086 
0087 /*`
0088 [heading Constraints]
0089 * `T` may be any type except `void`
0090 * `C` must be a user-defined type
0091 
0092 [heading Behavior]
0093 * A substitution failure occurs if the constraints are violated.
0094 * When `T` is a function, function pointer (unqualified), or function reference, then the aliased type is a member function pointer of `C` with the same parameters and return type.
0095 * When `T` is a member function pointer (unqualified)  of any type, the aliased type is a member function pointer of `C` with the same parameters and return type.
0096 * Otherwise, the aliased type is a member data pointer equivalent to `std::remove_reference_t<T> C::*`.
0097 
0098 [heading Input/Output Examples]
0099 [table
0100     [[`T`]                              [`apply_member_pointer_t<T, foo>`]]
0101     [[`int()`]                          [`int(foo::*)()`]]
0102     [[`int (&)()`]                      [`int(foo::*)()`]]
0103     [[`int (*)()`]                      [`int(foo::*)()`]]
0104     [[`int(bar::*)()`]                  [`int(foo::*)()`]]
0105     [[`int(bar::*)() &`]                [`int(foo::*)() &`]]
0106     [[`int(bar::*)() &&`]               [`int(foo::*)() &&`]]
0107     [[`int(bar::*)() const`]            [`int(foo::*)() const`]]
0108     [[`int(bar::*)() transaction_safe`] [`int(foo::*)() transaction_safe`]]
0109     [[`int bar::*`]                     [`int foo::*`]]
0110     [[`int`]                            [`int foo::*`]]
0111     [[`int &`]                          [`int foo::*`]]
0112     [[`const int &`]                    [`const int foo::*`]]
0113     [[`int (*const)()`]                 [`int (*const foo::*)()`]]
0114     [[`void`]                           [(substitution failure)]]
0115 ]
0116 
0117 [heading Example Program]
0118 [import ../example/apply_member_pointer.cpp]
0119 [apply_member_pointer]
0120 [endsect]
0121 */
0122 //]
0123 #endif