userver: userver/formats/serialize/variant.hpp Source File
Loading...
Searching...
No Matches
variant.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/formats/serialize/variant.hpp
4/// @brief Serializers for std::variant
5/// @ingroup userver_universal userver_formats_serialize
6
7#include <variant>
8
9#include <userver/formats/serialize/to.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace formats::serialize {
14
15template <typename Value, typename... Types>
16Value Serialize(const std::variant<Types...>& value, To<Value>) {
17 return std::visit([](const auto& item) { return typename Value::Builder(item).ExtractValue(); }, value);
18}
19
20} // namespace formats::serialize
21
22USERVER_NAMESPACE_END