Short live q20::construct_at()!

Move the helper from qsystemsemaphore.cpp to q20memory.h
to prevent clashes in CMake Unity (Jumbo) builds.

Manual conflict resolutions:
  - file-local construct_at doesn't exist in 6.5

Task-number: QTBUG-109394
Change-Id: Id0127af1f0d51c87a5887090cc90ab232eff8093
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
(cherry picked from commit 72c2cdbc572f8b8b45a57a451e2bc19bb1c53b0c)
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
Friedemann Kleint 2023-01-27 10:50:51 +01:00 committed by Marc Mutz
parent db26a9c397
commit 1fa935d93e
2 changed files with 47 additions and 0 deletions

View File

@ -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

View File

@ -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 <QtCore/qxptype_traits.h>
#include <memory>
//
// 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 <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)
{
::new (const_cast<void*>(static_cast<const volatile void*>(ptr))) T(std::forward<Args>(args)...);
}
#endif
} // namespace q20
QT_END_NAMESPACE
#endif /* Q20MEMORY_H */