fpmas 1.6
functional.h
Go to the documentation of this file.
1#ifndef FPMAS_FUNCTIONAL_H
2#define FPMAS_FUNCTIONAL_H
3
8#include <utility>
9#include <functional>
10#include <vector>
11#include <unordered_map>
12#include <map>
13#include <set>
14
15namespace fpmas { namespace utils {
16
17 namespace detail {
21 template<typename Container>
22 struct Concat {
23 };
24
28 template<typename T, typename Alloc>
29 struct Concat<std::vector<T, Alloc>> {
33 static std::vector<T, Alloc> concat(
34 std::vector<T, Alloc>& init, const std::vector<T, Alloc>& c) {
35 init.insert(init.end(), c.begin(), c.end());
36 return std::move(init);
37 }
38 };
39
43 template<typename T, typename Comp, typename Alloc>
44 struct Concat<std::set<T, Comp, Alloc>> {
48 static std::set<T, Comp, Alloc> concat(
49 std::set<T, Comp, Alloc>& init,
50 const std::set<T, Comp, Alloc>& c) {
51 init.insert(c.begin(), c.end());
52 return std::move(init);
53 }
54 };
55
59 template<typename K, typename T, typename Comp, typename Alloc>
60 struct Concat<std::map<K, T, Comp, Alloc>> {
64 static std::map<K, T, Comp, Alloc> concat(
65 std::map<K, T, Comp, Alloc>& init,
66 const std::map<K, T, Comp, Alloc>& c
67 ) {
68 init.insert(c.begin(), c.end());
69 return std::move(init);
70 }
71 };
72
76 template<typename K, typename T, typename Hash, typename KeyEq, typename Alloc>
77 struct Concat<std::unordered_map<K, T, Hash, KeyEq, Alloc>> {
81 static std::unordered_map<K, T, Hash, KeyEq, Alloc> concat(
82 std::unordered_map<K, T, Hash, KeyEq, Alloc>& init,
83 const std::unordered_map<K, T, Hash, KeyEq, Alloc>& c
84 ) {
85 init.insert(c.begin(), c.end());
86 return std::move(init);
87 }
88 };
89 }
90
94 struct Concat {
110 template<typename Container>
111 Container operator()(Container& init, const Container& c) const {
113 }
114 };
115
120 template<typename T, typename Compare = std::less<T>>
121 struct Max {
126 T operator()(const T& a, const T& b) {
127 return std::max(a, b, Compare());
128 }
129 };
134 template<typename T, typename Compare = std::less<T>>
135 struct Min {
140 T operator()(const T& a, const T& b) {
141 return std::min(a, b, Compare());
142 }
143 };
144}}
145#endif
Definition: fpmas.cpp:3
void init(int argc, char **argv)
Definition: fpmas.cpp:6
Definition: functional.h:94
Container operator()(Container &init, const Container &c) const
Definition: functional.h:111
Definition: functional.h:121
T operator()(const T &a, const T &b)
Definition: functional.h:126
Definition: functional.h:135
T operator()(const T &a, const T &b)
Definition: functional.h:140
static std::map< K, T, Comp, Alloc > concat(std::map< K, T, Comp, Alloc > &init, const std::map< K, T, Comp, Alloc > &c)
Definition: functional.h:64
static std::set< T, Comp, Alloc > concat(std::set< T, Comp, Alloc > &init, const std::set< T, Comp, Alloc > &c)
Definition: functional.h:48
static std::unordered_map< K, T, Hash, KeyEq, Alloc > concat(std::unordered_map< K, T, Hash, KeyEq, Alloc > &init, const std::unordered_map< K, T, Hash, KeyEq, Alloc > &c)
Definition: functional.h:81
static std::vector< T, Alloc > concat(std::vector< T, Alloc > &init, const std::vector< T, Alloc > &c)
Definition: functional.h:33
Definition: functional.h:22