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,
32 std::pair<const K, V>&& elem) {
33 cont.insert(std::move(elem));
34}
35
36template <typename T, typename Comp, typename Alloc>
37void Insert(std::set<T, Comp, Alloc>& cont, T&& elem) {
38 cont.insert(std::forward<T>(elem));
39}
40
41template <typename T, typename Hash, typename Eq, typename Alloc>
42void Insert(std::unordered_set<T, Hash, Eq, Alloc>& cont, T&& elem) {
43 cont.insert(std::forward<T>(elem));
44}
45/// @}
46
47namespace impl {
48
49template <typename T>
50using InsertResult = decltype(dump::Insert(
51 std::declval<T&>(), std::declval<meta::RangeValueType<T>&&>()));
52
53} // namespace impl
54
55/// Check if a range is a container
56template <typename T>
57inline constexpr bool kIsContainer =
60
61} // namespace dump
62
63USERVER_NAMESPACE_END