zhangmeng
2021-07-02 056f71f24cefaf88f2a93714c6678c03ed5f1e0e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
 
@Copyright Barrett Adair 2015-2017
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
 
*/
 
#ifndef BOOST_CLBL_TRTS_DETAIL_UTILITY_HPP
#define BOOST_CLBL_TRTS_DETAIL_UTILITY_HPP
 
#include <boost/callable_traits/detail/config.hpp>
#include <boost/callable_traits/detail/sfinae_errors.hpp>
#include <boost/callable_traits/detail/qualifier_flags.hpp>
 
namespace boost { namespace callable_traits { namespace detail {
 
struct cdecl_tag{};
struct stdcall_tag{};
struct fastcall_tag{};
struct pascal_tag{};
 
struct invalid_type { invalid_type() = delete; };
struct reference_error { reference_error() = delete; };
 
template<typename T>
using error_type = typename std::conditional<
    std::is_reference<T>::value, reference_error, invalid_type>::type;
 
#ifdef BOOST_CLBL_TRTS_DISABLE_ABOMINABLE_FUNCTIONS
struct abominable_functions_not_supported_on_this_compiler{};
#endif
 
// used to convey "this type doesn't matter" in code
struct dummy {};
 
// used as return type in failed SFINAE tests
struct substitution_failure : std::false_type{};
 
template<bool Value>
using bool_type = std::integral_constant<bool, Value>;
 
// shorthand for std::tuple_element
template<std::size_t I, typename Tup>
using at = typename std::tuple_element<I, Tup>::type;
 
template<typename T, typename Class>
using add_member_pointer = T Class::*;
 
template<typename L, typename R, typename ErrorType>
 using fail_when_same = fail_if<std::is_same<L, R>::value, ErrorType>;
 
template<typename T, typename ErrorType,
    typename U = typename std::remove_reference<T>::type>
using try_but_fail_if_invalid = sfinae_try<T,
    fail_when_same<U, invalid_type, ErrorType>,
    fail_when_same<U, reference_error,
        reference_type_not_supported_by_this_metafunction>>;
 
template<typename T, typename ErrorType,
    typename U = typename std::remove_reference<T>::type,
    bool is_reference_error = std::is_same<reference_error, U>::value>
using fail_if_invalid = fail_if<
    std::is_same<U, invalid_type>::value || is_reference_error,
    typename std::conditional<is_reference_error,
        reference_type_not_supported_by_this_metafunction, ErrorType>::type>;
 
template<typename T, typename Fallback>
using fallback_if_invalid = typename std::conditional<
    std::is_same<T, invalid_type>::value, Fallback, T>::type;
 
template<typename T, template<class> class Alias, typename U = Alias<T>>
struct force_sfinae {
    using type = U;
};
 
template<typename T>
using shallow_decay = typename std::remove_cv<
    typename std::remove_reference<T>::type>::type;
 
template<typename T>
struct is_reference_wrapper_t {
    using type = std::false_type;
};
 
template<typename T>
struct is_reference_wrapper_t<std::reference_wrapper<T>> {
    using type = std::true_type;
};
 
template<typename T>
using is_reference_wrapper =
    typename is_reference_wrapper_t<shallow_decay<T>>::type;
 
template<typename T, typename = std::true_type>
struct unwrap_reference_t {
    using type = T;
};
 
template<typename T>
struct unwrap_reference_t<T, is_reference_wrapper<T>> {
    using type = decltype(std::declval<T>().get());
};
 
// removes std::reference_wrapper
template<typename T>
using unwrap_reference = typename unwrap_reference_t<T>::type;
 
}}} // namespace boost::callable_traits::detail
 
#endif // #ifndef BOOST_CLBL_TRTS_DETAIL_UTILITY_HPP