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
#include <vector>
#include <iostream>
template<typename T>
struct MapTtoT { typedef T (type)(const T); };
template<typename F, typename T>
auto map_vec(F&& fnc, const std::vector<T>& source) -> decltype(void(fnc(std::declval<T>())), std::vector<T>())
{
std::vector<T> dest;
dest.reserve(source.size());
for (const auto i : source)
{
dest.emplace_back(fnc(i));
}
return dest;
}
template<typename T>
struct MapTandVectoT { typedef T (type)(const T, const std::vector<T>&); };
template<typename F, typename T>
auto map_vec(F&& fnc, const std::vector<T>& source) -> decltype(void(fnc(std::declval<T>(), source)), std::vector<T>())
{
std::vector<T> dest;
dest.reserve(source.size());
for (const auto i : source)
{
dest.emplace_back(fnc(i, source));
}
return dest;
}
class AddNum
{
public:
AddNum(const int num) : num_(num) {}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
g++-4.9 -std=c++14  -O2 -Wall -Wextra -pedantic -pthread -pedantic-errors main.cpp -lm  && ./a.out