Menu

[94f52a]: / append.hpp  Maximize  Restore  History

Download this file

82 lines (65 with data), 2.0 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef CHILON_APPEND_HPP
#define CHILON_APPEND_HPP
#include <chilon/meta/return.hpp>
#include <vector>
#include <unordered_map>
#include <type_traits>
namespace chilon {
namespace detail { struct appendable {}; }
template <class K>
struct key_collision {
key_collision(K const& key) : key_(key) {};
K const key_;
};
template <class K>
void throw_key_collision(K const& key) {
throw key_collision<K>(key);
}
template <class T, class U>
static inline
CHILON_RETURN_REQUIRE(void, std::is_base_of<detail::appendable, T>)
append(T& src, U const& dest) {
T::append_type::exec(src, dest);
}
template <class T, class U>
static inline
CHILON_RETURN_REQUIRE(void, std::is_base_of<detail::appendable, T>)
append(T& src, U&& dest) {
T::append_type::exec(src, std::move(dest));
}
template <class T>
static inline void append(std::vector<T>& dest, std::vector<T> const& src) {
for (auto i = src.begin(); i != src.end(); ++i) dest.push_back(*i);
}
template <class T>
static inline void append(std::vector<T>& dest, std::vector<T>&& src) {
for (auto i = src.begin(); i != src.end(); ++i) dest.push_back(std::move(*i));
}
template <class T, class U>
static inline void append_map(T& t, U const& u) {
for (auto it = u.begin(); it != u.end(); ++it) {
if (! t.insert(*it).second)
throw_key_collision(it->first);
}
}
template <class T, class U>
static inline void append_map(T& t, U&& u) {
for (auto it = u.begin(); it != u.end(); ++it) {
if (! t.emplace(std::move(*it)).second)
throw_key_collision(it->first);
}
}
template <class U, class K, class V, class _H, class A>
static inline void append(std::unordered_map<K, V, _H, A>& t, U const& u) {
append_map(t, u);
}
template <class U, class K, class V, class _H, class A>
static inline void append(std::unordered_map<K, V, _H, A>& t, U&& u) {
append_map(t, u);
}
template <class T>
struct appendable : detail::appendable {
typedef T append_type;
};
}
#endif
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.