From 29e0cca0ed5b43972e6e78900611fa39802cce0c Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 13 Dec 2019 19:32:06 +0100 Subject: Short live the Qt implementation of the Detection Idiom These never made it into the IS, but are still available in the Library Fundamentals TSs. Use them to simplify detection code in qcontainertools_impl.h. Change-Id: Iee83bc93c2abca34446d31912a2e04f6e3fe71de Reviewed-by: Thiago Macieira --- src/corelib/global/qxptype_traits.h | 63 +++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/corelib/global/qxptype_traits.h (limited to 'src/corelib/global/qxptype_traits.h') diff --git a/src/corelib/global/qxptype_traits.h b/src/corelib/global/qxptype_traits.h new file mode 100644 index 0000000000..7da0478583 --- /dev/null +++ b/src/corelib/global/qxptype_traits.h @@ -0,0 +1,63 @@ +// Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz +// 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 QXPTYPE_TRAITS_H +#define QXPTYPE_TRAITS_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 + +// like std::experimental::{nonesuch,is_detected/_v}(LFTSv2) +namespace qxp { + +struct nonesuch { + ~nonesuch() = delete; + nonesuch(const nonesuch&) = delete; + void operator=(const nonesuch&) = delete; +}; + +namespace _detail { + template class Op, typename...Args> + struct detector { + using value_t = std::false_type; + using type = T; + }; + template class Op, typename...Args> + struct detector>, Op, Args...> { + using value_t = std::true_type; + using type = Op; + }; +} // namespace _detail + +template