11#include <boost/variant/variant.hpp>
13#include <userver/compiler/demangle.hpp>
14#include <userver/formats/parse/variant.hpp>
16USERVER_NAMESPACE_BEGIN
18namespace formats::
parse {
21template <
class T,
class Value,
typename Result>
22void ParseBoostVariantSingle(
const Value& value,
23 std::optional<Result>& result) {
25 std::type_index old_type = result->type();
27 value.
template As<T>();
28 }
catch (
const std::exception&) {
32 ThrowVariantAmbiguousParse<
typename Value::ParseException, Result, T>(
33 value.GetPath(), old_type);
37 result = value.
template As<T>();
38 }
catch (
const std::exception&) {
45template <
class Value,
typename... Types>
46boost::variant<Types...> Parse(
const Value& value,
47 formats::
parse::
To<boost::variant<Types...>>) {
48 std::optional<boost::variant<Types...>> result;
49 (impl::ParseBoostVariantSingle<Types>(value, result), ...);
52 ThrowVariantParseException<
typename Value::ParseException,
53 boost::variant<Types...>>(value.GetPath());
56 return std::move(*result);