diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/jobs/basejob.cpp | 13 | ||||
-rw-r--r-- | lib/quotient_common.h | 27 |
2 files changed, 25 insertions, 15 deletions
diff --git a/lib/jobs/basejob.cpp b/lib/jobs/basejob.cpp index 9a7b9b5e..400a9243 100644 --- a/lib/jobs/basejob.cpp +++ b/lib/jobs/basejob.cpp @@ -5,6 +5,7 @@ #include "basejob.h" #include "connectiondata.h" +#include "quotient_common.h" #include <QtCore/QRegularExpression> #include <QtCore/QTimer> @@ -15,8 +16,6 @@ #include <QtNetwork/QNetworkReply> #include <QtNetwork/QNetworkRequest> -#include <array> - using namespace Quotient; using std::chrono::seconds, std::chrono::milliseconds; using namespace std::chrono_literals; @@ -63,12 +62,6 @@ QDebug BaseJob::Status::dumpToLog(QDebug dbg) const return dbg << ": " << message; } -template <typename... Ts> -constexpr auto make_array(Ts&&... items) -{ - return std::array<std::common_type_t<Ts...>, sizeof...(Ts)>({items...}); -} - class BaseJob::Private { public: struct JobTimeoutConfig { @@ -163,8 +156,8 @@ public: { // FIXME: use std::array {} when Apple stdlib gets deduction guides for it static const auto verbs = - make_array(QStringLiteral("GET"), QStringLiteral("PUT"), - QStringLiteral("POST"), QStringLiteral("DELETE")); + to_array({ QStringLiteral("GET"), QStringLiteral("PUT"), + QStringLiteral("POST"), QStringLiteral("DELETE") }); const auto verbWord = verbs.at(size_t(verb)); return verbWord % ' ' % (reply ? reply->url().toString(QUrl::RemoveQuery) diff --git a/lib/quotient_common.h b/lib/quotient_common.h index 789128cf..037d5ded 100644 --- a/lib/quotient_common.h +++ b/lib/quotient_common.h @@ -8,6 +8,24 @@ namespace Quotient { Q_NAMESPACE +namespace impl { + template <class T, std::size_t N, std::size_t... I> + constexpr std::array<std::remove_cv_t<T>, N> + to_array_impl(T (&&a)[N], std::index_sequence<I...>) + { + return { {std::move(a[I])...} }; + } +} +// std::array {} needs explicit template parameters on macOS because +// Apple stdlib doesn't have deduction guides for std::array; to alleviate that, +// to_array() is borrowed from C++20 (thanks to cppreference for the possible +// implementation: https://en.cppreference.com/w/cpp/container/array/to_array) +template <typename T, size_t N> +constexpr auto to_array(T (&& items)[N]) +{ + return impl::to_array_impl(std::move(items), std::make_index_sequence<N>{}); +} + // TODO: code like this should be generated from the CS API definition //! \brief Membership states @@ -29,10 +47,9 @@ enum class Membership : unsigned int { Q_DECLARE_FLAGS(MembershipMask, Membership) Q_FLAG_NS(MembershipMask) -constexpr inline std::array MembershipStrings = { +constexpr inline auto MembershipStrings = to_array( // The order MUST be the same as the order in the original enum - "join", "leave", "invite", "knock", "ban" -}; + { "join", "leave", "invite", "knock", "ban" }); //! \brief Local user join-state names //! @@ -49,10 +66,10 @@ enum class JoinState : std::underlying_type_t<Membership> { Q_DECLARE_FLAGS(JoinStates, JoinState) Q_FLAG_NS(JoinStates) -constexpr inline std::array JoinStateStrings { +constexpr inline auto JoinStateStrings = to_array({ MembershipStrings[0], MembershipStrings[1], MembershipStrings[2], MembershipStrings[3] /* same as MembershipStrings, sans "ban" */ -}; +}); //! \brief Network job running policy flags //! |