// 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 QMINMAX_H #define QMINMAX_H #if 0 #pragma qt_class(QtMinMax) #pragma qt_sync_stop_processing #endif #include #include #include QT_BEGIN_NAMESPACE namespace QTypeTraits { namespace detail { template && std::is_arithmetic_v && std::is_floating_point_v == std::is_floating_point_v && std::is_signed_v == std::is_signed_v && !std::is_same_v && !std::is_same_v && !std::is_same_v && !std::is_same_v>> struct Promoted { using type = decltype(T() + U()); }; } template using Promoted = typename detail::Promoted::type; } template constexpr inline const T &qMin(const T &a, const T &b) { return (a < b) ? a : b; } template constexpr inline const T &qMax(const T &a, const T &b) { return (a < b) ? b : a; } template constexpr inline const T &qBound(const T &min, const T &val, const T &max) { Q_ASSERT(!(max < min)); return qMax(min, qMin(max, val)); } template constexpr inline QTypeTraits::Promoted qMin(const T &a, const U &b) { using P = QTypeTraits::Promoted; P _a = a; P _b = b; return (_a < _b) ? _a : _b; } template constexpr inline QTypeTraits::Promoted qMax(const T &a, const U &b) { using P = QTypeTraits::Promoted; P _a = a; P _b = b; return (_a < _b) ? _b : _a; } template constexpr inline QTypeTraits::Promoted qBound(const T &min, const U &val, const T &max) { Q_ASSERT(!(max < min)); return qMax(min, qMin(max, val)); } template constexpr inline QTypeTraits::Promoted qBound(const T &min, const T &val, const U &max) { using P = QTypeTraits::Promoted; Q_ASSERT(!(P(max) < P(min))); return qMax(min, qMin(max, val)); } template constexpr inline QTypeTraits::Promoted qBound(const U &min, const T &val, const T &max) { using P = QTypeTraits::Promoted; Q_ASSERT(!(P(max) < P(min))); return qMax(min, qMin(max, val)); } QT_END_NAMESPACE #endif // QMINMAX_H