userver: userver/dump/meta_containers.hpp Source File
Loading...
Searching...
No Matches
meta_containers.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/dump/meta_containers.hpp
4/// @brief Dump serialization customization points for STL containers
5
6#include <iterator>
7#include <map>
8#include <set>
9#include <type_traits>
10#include <unordered_map>
11#include <unordered_set>
12#include <utility>
13#include <vector>
14
15#include <userver/dump/meta.hpp>
16#include <userver/utils/meta.hpp>
17
18USERVER_NAMESPACE_BEGIN
19
20namespace dump {
21
22/// @{
23/// Customization point: insert an element into a container
24template <typename T, typename Alloc>
25void Insert(std::vector<T, Alloc>& cont, T&& elem) {
26 cont.push_back(std::forward<T>(elem));
27}
28
29template <typename K, typename V, typename Comp, typename Alloc>
30void Insert(std::map<K, V, Comp, Alloc>& cont, std::pair<const K, V>&& elem) {
31 cont.insert(std::move(elem));
32}
33
34template <typename K, typename V, typename Hash, typename Eq, typename Alloc>
35void Insert(std::unordered_map<K, V, Hash, Eq, Alloc>& cont, std::pair<const K, V>&& elem) {
36 cont.insert(std::move(elem));
37}
38
39template <typename T, typename Comp, typename Alloc>
40void Insert(std::set<T, Comp, Alloc>& cont, T&& elem) {
41 cont.insert(std::forward<T>(elem));
42}
43
44template <typename T, typename Hash, typename Eq, typename Alloc>
45void Insert(std::unordered_set<T, Hash, Eq, Alloc>& cont, T&& elem) {
46 cont.insert(std::forward<T>(elem));
47}
48/// @}
49
50/// Check if a range is a container
51template <typename T>
52concept IsContainer =
53 meta::kIsRange<T> && std::is_default_constructible_v<T> && meta::kIsSizable<T> &&
54 requires(T& t, meta::RangeValueType<T>&& v) { dump::Insert(t, std::move(v)); };
55
56} // namespace dump
57
58USERVER_NAMESPACE_END