diff options
author | Marc Mutz <marc.mutz@qt.io> | 2023-02-02 07:40:08 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2023-02-02 22:45:30 +0000 |
commit | 67ed712235375fa1d1b9ea0e5c71755886f65f83 (patch) | |
tree | 368a36975e5ac8214b5e28efa95a5940d213c3b2 | |
parent | c53fdcb5ee15c309ba68717fa6564dc1ff4b8618 (diff) |
q20::construct_at(): fix various issues
Fix several issues in 72c2cdbc572f8b8b45a57a451e2bc19bb1c53b0c,
which I was too slow to review before it went in:
- use the correct feature macro, not __cplusplus
- use the correct signature (return T*, not void)
- don't make the function static
- add a comment mentioning the material difference to std::construct_at
- drop unneeded <qxptype_traits.h> include
Pick-to: 6.5
Task-number: QTBUG-109394
Change-Id: I39d1908f565b1c1a31d5741924ac173447ec9057
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r-- | src/corelib/global/q20memory.h | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/corelib/global/q20memory.h b/src/corelib/global/q20memory.h index 438613db48..bb337a9f7f 100644 --- a/src/corelib/global/q20memory.h +++ b/src/corelib/global/q20memory.h @@ -4,9 +4,12 @@ #ifndef Q20MEMORY_H #define Q20MEMORY_H -#include <QtCore/qxptype_traits.h> +#include <QtCore/qtconfigmacros.h> #include <memory> +#include <utility> + +#include <type_traits> // // W A R N I N G @@ -26,19 +29,20 @@ QT_BEGIN_NAMESPACE +// like std::construct_at (but not whitelisted for constexpr) namespace q20 { - -#if __cplusplus >= 202002L +#ifdef __cpp_lib_constexpr_dynamic_alloc using std::construct_at; #else template <typename T, typename... Args, typename Enable = std::void_t<decltype(::new (std::declval<void *>()) T(std::declval<Args>()...))> > - static void construct_at(T *ptr, Args && ... args) +T *construct_at(T *ptr, Args && ... args) { - ::new (const_cast<void*>(static_cast<const volatile void*>(ptr))) T(std::forward<Args>(args)...); + return ::new (const_cast<void *>(static_cast<const volatile void *>(ptr))) + T(std::forward<Args>(args)...); } -#endif +#endif // __cpp_lib_constexpr_dynamic_alloc } // namespace q20 QT_END_NAMESPACE |