Warning, file /include/QtCore/q20memory.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005 #ifndef Q20MEMORY_H
0006 #define Q20MEMORY_H
0007
0008 #include <QtCore/qtconfigmacros.h>
0009
0010 #include <memory>
0011
0012 #include <type_traits>
0013 #include <utility>
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 QT_BEGIN_NAMESPACE
0032
0033
0034 namespace q20 {
0035 #ifdef __cpp_lib_constexpr_dynamic_alloc
0036 using std::construct_at;
0037 #else
0038 template <typename T,
0039 typename... Args,
0040 typename Enable = std::void_t<decltype(::new (std::declval<void *>()) T(std::declval<Args>()...))> >
0041 T *construct_at(T *ptr, Args && ... args)
0042 {
0043 return ::new (const_cast<void *>(static_cast<const volatile void *>(ptr)))
0044 T(std::forward<Args>(args)...);
0045 }
0046 #endif
0047 }
0048
0049
0050 namespace q20 {
0051
0052 #ifdef __cpp_lib_to_address
0053 using std::to_address;
0054 #else
0055
0056 template <typename T>
0057 constexpr T *to_address(T *p) noexcept {
0058
0059
0060 static_assert(!std::is_function_v<T>, "to_address must not be used on function types");
0061 return p;
0062 }
0063
0064 template <typename Ptr, typename std::enable_if_t<!std::is_pointer_v<Ptr>, bool> = true>
0065 constexpr auto to_address(const Ptr &ptr) noexcept;
0066
0067 namespace detail {
0068
0069 template <typename Ptr, typename = void>
0070 struct to_address_helper {
0071 static auto get(const Ptr &ptr) noexcept
0072 { return q20::to_address(ptr.operator->()); }
0073 };
0074 template <typename Ptr>
0075 struct to_address_helper<Ptr, std::void_t<
0076 decltype(std::pointer_traits<Ptr>::to_address(std::declval<const Ptr&>()))
0077 >>
0078 {
0079 static auto get(const Ptr &ptr) noexcept
0080 { return std::pointer_traits<Ptr>::to_address(ptr); }
0081 };
0082 }
0083
0084 template <typename Ptr, typename std::enable_if_t<!std::is_pointer_v<Ptr>, bool>>
0085 constexpr auto to_address(const Ptr &ptr) noexcept
0086 { return detail::to_address_helper<Ptr>::get(ptr); }
0087
0088 #endif
0089 }
0090
0091 QT_END_NAMESPACE
0092
0093 #endif