From bf92abdb2c52b402b5b599e82cfde60b01f0301f Mon Sep 17 00:00:00 2001 From: ado Date: Sun, 20 Dec 2020 03:16:17 +0100 Subject: [PATCH] add variant support --- include/ss/extract.hpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/include/ss/extract.hpp b/include/ss/extract.hpp index 4c84128..966f37b 100644 --- a/include/ss/extract.hpp +++ b/include/ss/extract.hpp @@ -7,6 +7,7 @@ #include #include #include +#include namespace ss { @@ -315,7 +316,8 @@ struct unsupported_type { template std::enable_if_t && !std::is_floating_point_v && - !is_instance_of::value, + !is_instance_of::value && + !is_instance_of::value, bool> extract(const char*, const char*, T&) { static_assert(error::unsupported_type::value, @@ -346,6 +348,25 @@ std::enable_if_t::value, bool> extract( return true; } +template +bool extract_variant(const char* begin, const char* end, T& value) { + using IthType = std::variant_alternative_t>; + IthType ithValue; + if (extract(begin, end, ithValue)) { + value = ithValue; + return true; + } else if constexpr (I + 1 < std::variant_size_v) { + return extract_variant(begin, end, value); + } + return false; +} + +template +std::enable_if_t::value, bool> extract( + const char* begin, const char* end, T& value) { + return extract_variant(begin, end, value); +} + //////////////// // extract specialization ////////////////