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