diff --git a/src/corelib/CMakeLists.txt b/src/corelib/CMakeLists.txt index cc6ca07feb..f4682e2e99 100644 --- a/src/corelib/CMakeLists.txt +++ b/src/corelib/CMakeLists.txt @@ -104,6 +104,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 0000000000..438613db48 --- /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 */ diff --git a/src/corelib/ipc/qsystemsemaphore.cpp b/src/corelib/ipc/qsystemsemaphore.cpp index 6607222580..fed4f41496 100644 --- a/src/corelib/ipc/qsystemsemaphore.cpp +++ b/src/corelib/ipc/qsystemsemaphore.cpp @@ -5,25 +5,16 @@ #include "qsystemsemaphore_p.h" #if QT_CONFIG(systemsemaphore) -#include +#include QT_BEGIN_NAMESPACE using namespace QtIpcCommon; using namespace Qt::StringLiterals; -#if __cplusplus >= 202002L -using std::construct_at; -#else -template static void construct_at(T *ptr) -{ - new (ptr) T; -} -#endif - inline void QSystemSemaphorePrivate::constructBackend() { - visit([](auto p) { construct_at(p); }); + visit([](auto p) { q20::construct_at(p); }); } inline void QSystemSemaphorePrivate::destructBackend()