11#include <boost/variant/variant.hpp>
13#include <userver/compiler/demangle.hpp>
14#include <userver/formats/parse/variant.hpp>
16USERVER_NAMESPACE_BEGIN
21template <
class T,
class Value,
typename Result>
22void ParseBoostVariantSingle(
const Value& value, std::optional<Result>& result) {
24 std::type_index old_type = result->type();
26 value.
template As<T>();
27 }
catch (
const std::exception&) {
31 ThrowVariantAmbiguousParse<
typename Value::ParseException, Result, T>(value.GetPath(), old_type);
35 result = value.
template As<T>();
36 }
catch (
const std::exception&) {
43template <
class Value,
typename... Types>
44boost::variant<Types...> Parse(
const Value& value,
formats::
parse::
To<boost::variant<Types...>>) {
45 std::optional<boost::variant<Types...>> result;
46 (impl::ParseBoostVariantSingle<Types>(value, result), ...);
49 ThrowVariantParseException<
typename Value::ParseException, boost::variant<Types...>>(value.GetPath());
52 return std::move(*result);