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(
18 [](const auto& item) {
19 return typename Value::Builder(item).ExtractValue();
20 },
21 value);
22}
23
24} // namespace formats::serialize
25
26USERVER_NAMESPACE_END