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_DETAIL_UTILITY_HPP
0010 #define BOOST_CLBL_TRTS_DETAIL_UTILITY_HPP
0011 
0012 #include <boost/callable_traits/detail/config.hpp>
0013 #include <boost/callable_traits/detail/sfinae_errors.hpp>
0014 #include <boost/callable_traits/detail/qualifier_flags.hpp>
0015 
0016 namespace boost { namespace callable_traits { namespace detail {
0017 
0018 struct cdecl_tag{};
0019 struct stdcall_tag{};
0020 struct fastcall_tag{};
0021 struct pascal_tag{};
0022 
0023 struct invalid_type { invalid_type() = delete; };
0024 struct reference_error { reference_error() = delete; };
0025 
0026 template<typename T>
0027 using error_type = typename std::conditional<
0028     std::is_reference<T>::value, reference_error, invalid_type>::type;
0029 
0030 #ifdef BOOST_CLBL_TRTS_DISABLE_ABOMINABLE_FUNCTIONS
0031 struct abominable_functions_not_supported_on_this_compiler{};
0032 #endif
0033 
0034 // used to convey "this type doesn't matter" in code
0035 struct dummy {};
0036 
0037 // used as return type in failed SFINAE tests
0038 struct substitution_failure : std::false_type{};
0039 
0040 template<bool Value>
0041 using bool_type = std::integral_constant<bool, Value>;
0042 
0043 // shorthand for std::tuple_element
0044 template<std::size_t I, typename Tup>
0045 using at = typename std::tuple_element<I, Tup>::type;
0046 
0047 template<typename T, typename Class>
0048 using add_member_pointer = T Class::*;
0049 
0050 template<typename L, typename R, typename ErrorType>
0051  using fail_when_same = fail_if<std::is_same<L, R>::value, ErrorType>;
0052 
0053 template<typename T, typename ErrorType,
0054     typename U = typename std::remove_reference<T>::type>
0055 using try_but_fail_if_invalid = sfinae_try<T,
0056     fail_when_same<U, invalid_type, ErrorType>,
0057     fail_when_same<U, reference_error,
0058         reference_type_not_supported_by_this_metafunction>>;
0059 
0060 template<typename T, typename ErrorType,
0061     typename U = typename std::remove_reference<T>::type,
0062     bool is_reference_error = std::is_same<reference_error, U>::value>
0063 using fail_if_invalid = fail_if<
0064     std::is_same<U, invalid_type>::value || is_reference_error,
0065     typename std::conditional<is_reference_error,
0066         reference_type_not_supported_by_this_metafunction, ErrorType>::type>;
0067 
0068 template<typename T, typename Fallback>
0069 using fallback_if_invalid = typename std::conditional<
0070     std::is_same<T, invalid_type>::value, Fallback, T>::type;
0071 
0072 template<typename T, template<class> class Alias, typename U = Alias<T>>
0073 struct force_sfinae {
0074     using type = U;
0075 };
0076 
0077 template<typename T>
0078 using shallow_decay = typename std::remove_cv<
0079     typename std::remove_reference<T>::type>::type;
0080 
0081 template<typename T>
0082 struct is_reference_wrapper_t {
0083     using type = std::false_type;
0084 };
0085 
0086 template<typename T>
0087 struct is_reference_wrapper_t<std::reference_wrapper<T>> {
0088     using type = std::true_type;
0089 };
0090 
0091 template<typename T>
0092 using is_reference_wrapper =
0093     typename is_reference_wrapper_t<shallow_decay<T>>::type;
0094 
0095 template<typename T, typename = std::true_type>
0096 struct unwrap_reference_t {
0097     using type = T;
0098 };
0099 
0100 template<typename T>
0101 struct unwrap_reference_t<T, is_reference_wrapper<T>> {
0102     using type = decltype(std::declval<T>().get());
0103 };
0104 
0105 // removes std::reference_wrapper
0106 template<typename T>
0107 using unwrap_reference = typename unwrap_reference_t<T>::type;
0108 
0109 }}} // namespace boost::callable_traits::detail
0110 
0111 #endif // #ifndef BOOST_CLBL_TRTS_DETAIL_UTILITY_HPP