// Copyright (C) 2022 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 QTTYPETRAITS_H #define QTTYPETRAITS_H #include #include #include #include #if 0 #pragma qt_class(QtTypeTraits) #pragma qt_sync_stop_processing #endif QT_BEGIN_NAMESPACE // like std::to_underlying template constexpr std::underlying_type_t qToUnderlying(Enum e) noexcept { return static_cast>(e); } #ifndef QT_NO_QASCONST #if QT_DEPRECATED_SINCE(6, 6) // this adds const to non-const objects (like std::as_const) template QT_DEPRECATED_VERSION_X_6_6("Use std::as_const() instead.") constexpr typename std::add_const::type &qAsConst(T &t) noexcept { return t; } // prevent rvalue arguments: template void qAsConst(const T &&) = delete; #endif // QT_DEPRECATED_SINCE(6, 6) #endif // QT_NO_QASCONST #ifndef QT_NO_QEXCHANGE // like std::exchange template constexpr T qExchange(T &t, U &&newValue) noexcept(std::conjunction_v, std::is_nothrow_assignable>) { T old = std::move(t); t = std::forward(newValue); return old; } #endif // QT_NO_QEXCHANGE namespace QtPrivate { // helper to be used to trigger a "dependent static_assert(false)" // (for instance, in a final `else` branch of a `if constexpr`.) template struct type_dependent_false : std::false_type {}; template struct value_dependent_false : std::false_type {}; } QT_END_NAMESPACE #endif // QTTYPETRAITS_H