File indexing completed on 2025-12-15 10:26:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef RANGES_V3_UTILITY_ADDRESSOF_HPP
0013 #define RANGES_V3_UTILITY_ADDRESSOF_HPP
0014
0015 #include <memory>
0016 #include <type_traits>
0017
0018 #include <concepts/concepts.hpp>
0019
0020 #include <range/v3/range_fwd.hpp>
0021
0022 #include <range/v3/detail/config.hpp>
0023
0024 #include <range/v3/detail/prologue.hpp>
0025
0026 namespace ranges
0027 {
0028
0029 namespace detail
0030 {
0031 #ifdef __cpp_lib_addressof_constexpr
0032 using std::addressof;
0033 #else
0034 namespace check_addressof
0035 {
0036 inline ignore_t operator&(ignore_t)
0037 {
0038 return {};
0039 }
0040 template<typename T>
0041 auto addressof(T & t)
0042 {
0043 return &t;
0044 }
0045 }
0046
0047 template<typename T>
0048 constexpr bool has_bad_addressof()
0049 {
0050 return !std::is_scalar<T>::value &&
0051 !RANGES_IS_SAME(decltype(check_addressof::addressof(*(T *)nullptr)),
0052 ignore_t);
0053 }
0054
0055 template(typename T)(
0056 requires(has_bad_addressof<T>()))
0057 T * addressof(T & arg) noexcept
0058 {
0059 return std::addressof(arg);
0060 }
0061
0062 template(typename T)(
0063 requires (!has_bad_addressof<T>()))
0064 constexpr T * addressof(T & arg) noexcept
0065 {
0066 return &arg;
0067 }
0068
0069 template<typename T>
0070 T const * addressof(T const &&) = delete;
0071 #endif
0072 }
0073
0074 }
0075
0076 #include <range/v3/detail/epilogue.hpp>
0077
0078 #endif