userver: userver/chaotic/io/userver/utils/default_dict.hpp Source File
Loading...
Searching...
No Matches
default_dict.hpp
1#pragma once
2
3#include <userver/chaotic/convert/to.hpp>
4#include <userver/utils/default_dict.hpp>
5#include <userver/utils/meta.hpp>
6
7USERVER_NAMESPACE_BEGIN
8
9namespace utils {
10
11template <typename T, typename U>
12DefaultDict<T> Convert(const U& value, chaotic::convert::To<DefaultDict<T>>) {
13 auto& extra = value.extra;
14 auto dict = DefaultDict<T>{{extra.begin(), extra.end()}};
15
16 if constexpr (meta::kIsOptional<decltype(value.__default__)>) {
17 if (value.__default__) dict.SetDefault(*value.__default__);
18 } else {
19 dict.SetDefault(value.__default__);
20 }
21
22 return dict;
23}
24
25template <typename T, typename U>
26U Convert(const DefaultDict<T>& value, chaotic::convert::To<U>) {
27 U u;
28 u.extra = {value.begin(), value.end()};
29 if (value.HasDefaultValue()) u.__default__ = value.GetDefaultValue();
30 return u;
31}
32
33} // namespace utils
34
35USERVER_NAMESPACE_END