aboutsummaryrefslogtreecommitdiff
path: root/lib/converters.h
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2019-10-29 22:04:40 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2019-11-01 08:43:09 +0900
commit60bb1cf942ad0815dcf42cbfe8acd1e076d848cf (patch)
tree3998826b6b78d9f7d3100570aa28aa86f8b040fd /lib/converters.h
parent8a574f8727cc8b1c91acf0840e99c9382c289098 (diff)
downloadlibquotient-60bb1cf942ad0815dcf42cbfe8acd1e076d848cf.tar.gz
libquotient-60bb1cf942ad0815dcf42cbfe8acd1e076d848cf.zip
Derive Omittable<> from std::optional<>
That breaks API all over the place but: 1. The fixes are trivial. 2. More of std:: is used instead of home-baking the same stuff.
Diffstat (limited to 'lib/converters.h')
-rw-r--r--lib/converters.h24
1 files changed, 3 insertions, 21 deletions
diff --git a/lib/converters.h b/lib/converters.h
index b753a80b..157bff27 100644
--- a/lib/converters.h
+++ b/lib/converters.h
@@ -206,7 +206,7 @@ template <typename T>
struct JsonConverter<Omittable<T>> {
static QJsonValue dump(const Omittable<T>& from)
{
- return from.omitted() ? QJsonValue() : toJson(from.value());
+ return from.has_value() ? toJson(from.value()) : QJsonValue();
}
static Omittable<T> load(const QJsonValue& jv)
{
@@ -378,28 +378,10 @@ namespace _impl {
static void impl(ContT& container, const QString& key,
const OmittableT& value)
{
- if (!value.omitted())
- addTo(container, key, value.value());
+ if (value)
+ addTo(container, key, *value);
}
};
-
-#if 0
- // This is a special one that unfolds optional<>
- template <typename ValT, bool Force>
- struct AddNode<optional<ValT>, Force>
- {
- template <typename ContT, typename OptionalT>
- static void impl(ContT& container,
- const QString& key, const OptionalT& value)
- {
- if (value)
- AddNode<ValT>::impl(container, key, value.value());
- else if (Force) // Edge case, no value but must put something
- AddNode<ValT>::impl(container, key, QString{});
- }
- };
-#endif
-
} // namespace _impl
static constexpr bool IfNotEmpty = false;