Short live q20::construct_at()!

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

Pick-to: 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>
This commit is contained in:
Friedemann Kleint 2023-01-27 10:50:51 +01:00
parent cebc6b83bf
commit 72c2cdbc57
3 changed files with 49 additions and 11 deletions

View File

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

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 */

View File

@ -5,25 +5,16 @@
#include "qsystemsemaphore_p.h"
#if QT_CONFIG(systemsemaphore)
#include <memory>
#include <QtCore/q20memory.h>
QT_BEGIN_NAMESPACE
using namespace QtIpcCommon;
using namespace Qt::StringLiterals;
#if __cplusplus >= 202002L
using std::construct_at;
#else
template <typename T> 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()