diff --git a/src/corelib/CMakeLists.txt b/src/corelib/CMakeLists.txt index 56daff4f836..59362e02f48 100644 --- a/src/corelib/CMakeLists.txt +++ b/src/corelib/CMakeLists.txt @@ -103,6 +103,7 @@ qt_internal_add_module(Core global/q20algorithm.h global/q20functional.h global/q20iterator.h + global/q20memory.h global/q20type_traits.h global/q23functional.h global/qxpfunctional.h diff --git a/src/corelib/global/q20memory.h b/src/corelib/global/q20memory.h new file mode 100644 index 00000000000..438613db48b --- /dev/null +++ b/src/corelib/global/q20memory.h @@ -0,0 +1,46 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#ifndef Q20MEMORY_H +#define Q20MEMORY_H + +#include + +#include + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. Types and functions defined in this +// file can reliably be replaced by their std counterparts, once available. +// You may use these definitions in your own code, but be aware that we +// will remove them once Qt depends on the C++ version that supports +// them in namespace std. There will be NO deprecation warning, the +// definitions will JUST go away. +// +// If you can't agree to these terms, don't use these definitions! +// +// We mean it. +// + +QT_BEGIN_NAMESPACE + +namespace q20 { + +#if __cplusplus >= 202002L +using std::construct_at; +#else +template ()) T(std::declval()...))> > + static void construct_at(T *ptr, Args && ... args) +{ + ::new (const_cast(static_cast(ptr))) T(std::forward(args)...); +} +#endif +} // namespace q20 + +QT_END_NAMESPACE + +#endif /* Q20MEMORY_H */