From 08fb435749f33ee5d266bbc2ea63c7c42169be97 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Fri, 23 Mar 2018 23:15:24 +0900 Subject: converters.h: Make the default toJson() less greedy template toJson(T&&) grabbed even things that it cannot convert, leading to unpleasant effects in a situation when all that was needed was one implicit conversion (e.g. from QList to QStringList). So now it's three trivial toJson() overloads instead of a template. --- converters.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/converters.h b/converters.h index 96efe5f8..f7d99f48 100644 --- a/converters.h +++ b/converters.h @@ -24,14 +24,13 @@ namespace QMatrixClient { - template - inline QJsonValue toJson(T&& val) - { - return QJsonValue(std::forward(val)); - } + // This catches anything implicitly convertible to QJsonValue/Object/Array + inline QJsonValue toJson(const QJsonValue& val) { return val; } + inline QJsonObject toJson(const QJsonObject& o) { return o; } + inline QJsonArray toJson(const QJsonArray& arr) { return arr; } template - inline QJsonValue toJson(const QVector& vals) + inline QJsonArray toJson(const QVector& vals) { QJsonArray ar; for (const auto& v: vals) @@ -39,7 +38,7 @@ namespace QMatrixClient return ar; } - inline QJsonValue toJson(const QStringList& strings) + inline QJsonArray toJson(const QStringList& strings) { return QJsonArray::fromStringList(strings); } @@ -50,7 +49,7 @@ namespace QMatrixClient } template - inline QJsonValue toJson(const QHash& hashMap) + inline QJsonObject toJson(const QHash& hashMap) { QJsonObject json; for (auto it = hashMap.begin(); it != hashMap.end(); ++it) -- cgit v1.2.3