// Copyright (C) 2020 Mikhail Svetkin // Copyright (C) 2019 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QHTTPSERVERVIEWTRAITS_IMPL_H #define QHTTPSERVERVIEWTRAITS_IMPL_H #include #include #include #include #include #include QT_BEGIN_NAMESPACE namespace QtPrivate { template struct FunctionTraitsHelper { static constexpr const int ArgumentCount = sizeof ... (Args); static constexpr const int ArgumentIndexMax = ArgumentCount - 1; using ReturnType = ReturnT; template struct Arg { using Type = typename std::tuple_element>::type; using CleanType = q20::remove_cvref_t; static constexpr bool CopyConstructible = std::is_copy_constructible_v; }; }; template struct FunctionTraitsImpl; template struct FunctionTraitsImpl : public FunctionTraitsImpl { }; template struct FunctionTraitsImpl : public FunctionTraitsHelper { }; template struct FunctionTraitsImpl : public FunctionTraitsHelper { }; template struct FunctionTraitsImpl : public FunctionTraitsHelper { }; template using FunctionTraits = FunctionTraitsImpl>; template struct CheckAny { static constexpr bool Value = (T::Value || ...); static constexpr bool Valid = (T::Valid || ...); static constexpr bool StaticAssert = (T::StaticAssert || ...); }; template struct ViewTraits { using FTraits = FunctionTraits; using ArgumentIndexes = typename std::make_index_sequence; template struct SpecialHelper { using Arg = typename FTraits::template Arg; using CleanSpecialT = q20::remove_cvref_t; static constexpr bool TypeMatched = std::is_same::value; static constexpr bool TypeCVRefMatched = std::is_same::value; static constexpr bool ValidPosition = (I == FTraits::ArgumentIndexMax || I == FTraits::ArgumentIndexMax - 1); static constexpr bool ValidAll = TypeCVRefMatched && ValidPosition; static constexpr bool AssertCondition = DisableStaticAssert || !TypeMatched || TypeCVRefMatched; static constexpr bool AssertConditionOrder = DisableStaticAssert || !TypeMatched || ValidPosition; static constexpr bool StaticAssert = AssertCondition && AssertConditionOrder; static_assert(AssertConditionOrder, "ViewHandler arguments error: " "QHttpServerRequest or QHttpServerResponder" " can only be the last argument"); }; template struct Special { using Helper = SpecialHelper; static constexpr bool Value = Helper::TypeMatched; static constexpr bool Valid = Helper::ValidAll; static constexpr bool StaticAssert = Helper::StaticAssert; static constexpr bool AssertCondition = Helper::AssertCondition; }; }; } // namespace QtPrivate QT_END_NAMESPACE #endif // QHTTPSERVERVIEWTRAITS_IMPL_H