Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /*
0002 Defines `qualifier_flags`
0003 
0004 @Copyright Barrett Adair 2015-2017
0005 Distributed under the Boost Software License, Version 1.0.
0006 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
0007 
0008 */
0009 
0010 #ifndef BOOST_CLBL_TRTS_QUALIFIER_FLAGS_HPP
0011 #define BOOST_CLBL_TRTS_QUALIFIER_FLAGS_HPP
0012 
0013 #include <boost/callable_traits/detail/config.hpp>
0014 
0015 namespace boost { namespace callable_traits { namespace detail {
0016     
0017 //bit qualifier_flags used to signify cv/ref qualifiers
0018 using qualifier_flags = std::uint32_t;
0019 
0020 /*
0021     | && &  V  C |
0022 --------------------------------------------
0023 0   | 0  0  0  0 | default
0024 1   | 0  0  0  1 | const
0025 2   | 0  0  1  0 | volatile
0026 3   | 0  0  1  1 | const volatile
0027 --------------------------------------------
0028 4   | 0  1  0  0 | &
0029 5   | 0  1  0  1 | const &
0030 6   | 0  1  1  0 | volatile &
0031 7   | 0  1  1  1 | const volatile &
0032 --------------------------------------------
0033 8   | 1  0  0  0 | &&
0034 9   | 1  0  0  1 | const &&
0035 10  | 1  0  1  0 | volatile &&
0036 11  | 1  0  1  1 | const volatile &&
0037 
0038 */
0039 
0040 // Flag representing the default qualifiers on a type 
0041 // or member function overload.
0042 constexpr qualifier_flags default_ = 0;
0043 
0044 // Flag representing a const qualifier on a type or
0045 // member function overload.
0046 constexpr qualifier_flags const_ = 1;
0047 
0048 // Flag representing a volatile qualifier on a type
0049 // or member function overload.
0050 constexpr qualifier_flags volatile_ = 2;
0051 
0052 #ifdef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS
0053 
0054 constexpr qualifier_flags lref_ = default_;
0055 constexpr qualifier_flags rref_ = default_;
0056 #else
0057 
0058 // Flag representing an lvalue reference type, or
0059 // an lvalue-reference-qualified member function
0060 // overload.
0061 constexpr qualifier_flags lref_ = 4;
0062 
0063 // Flag representing an lvalue reference type, or
0064 // an rvalue-reference-qualified member function
0065 // overload.
0066 constexpr qualifier_flags rref_ = 8;
0067 
0068 #endif //#ifdef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS
0069 
0070 constexpr qualifier_flags cv_ = 3;
0071 
0072 template<qualifier_flags Flags>
0073 using remove_const_flag = std::integral_constant<
0074     qualifier_flags, Flags & ~const_>;
0075 
0076 template<qualifier_flags Flags>
0077 using is_const = std::integral_constant<bool,
0078     (Flags & const_) != 0>;
0079 
0080 template<qualifier_flags Flags>
0081 using remove_volatile_flag = std::integral_constant<
0082     qualifier_flags, Flags & ~volatile_>;
0083 
0084 template<typename U, typename T = typename std::remove_reference<U>::type>
0085 using cv_of = std::integral_constant<qualifier_flags,
0086     (std::is_const<T>::value ? const_ : default_)
0087     | (std::is_volatile<T>::value ? volatile_ : default_)>;
0088 
0089 template<typename T>
0090 using ref_of = std::integral_constant<qualifier_flags,
0091     std::is_rvalue_reference<T>::value ? rref_
0092     : (std::is_lvalue_reference<T>::value ? lref_
0093         : default_)>;
0094 
0095 //bit-flag implementation of C++11 reference collapsing rules
0096 template<qualifier_flags Existing,
0097          qualifier_flags Other,
0098          bool AlreadyHasRef = (Existing & (lref_ | rref_)) != 0,
0099          bool AlreadyHasLRef = (Existing & lref_) == lref_,
0100          bool IsAddingLRef = (Other & lref_) == lref_
0101 >
0102 using collapse_flags = std::integral_constant<qualifier_flags,
0103     !AlreadyHasRef ? (Existing | Other)
0104         : (AlreadyHasLRef ? (Existing | (Other & ~rref_))
0105             : (IsAddingLRef ? ((Existing & ~rref_) | Other )
0106                 : (Existing | Other)))>;
0107 
0108 template<typename T> struct flag_map { static constexpr qualifier_flags value = default_; };
0109 template<typename T> struct flag_map<T &> { static constexpr qualifier_flags value = lref_; };
0110 template<typename T> struct flag_map<T &&> { static constexpr qualifier_flags value = rref_; };
0111 template<typename T> struct flag_map<T const> { static constexpr qualifier_flags value = const_; };
0112 template<typename T> struct flag_map<T const &> { static constexpr qualifier_flags value = const_ | lref_; };
0113 template<typename T> struct flag_map<T const &&> { static constexpr qualifier_flags value = const_ | rref_; };
0114 template<typename T> struct flag_map<T volatile> { static constexpr qualifier_flags value = volatile_; };
0115 template<typename T> struct flag_map<T volatile &> { static constexpr qualifier_flags value = volatile_ | lref_; };
0116 template<typename T> struct flag_map<T volatile &&> { static constexpr qualifier_flags value = volatile_ | rref_; };
0117 template<typename T> struct flag_map<T const volatile> { static constexpr qualifier_flags value = const_ | volatile_; };
0118 template<typename T> struct flag_map<T const volatile &> { static constexpr qualifier_flags value = const_ | volatile_ | lref_; };
0119 template<typename T> struct flag_map<T const volatile &&> { static constexpr qualifier_flags value = const_ | volatile_ | rref_; };
0120 
0121 }}} // namespace boost::callable_traits::detail
0122 
0123 #endif // #ifndef BOOST_CLBL_TRTS_QUALIFIER_FLAGS_HPP