-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVectorM.h
More file actions
32 lines (25 loc) · 763 Bytes
/
VectorM.h
File metadata and controls
32 lines (25 loc) · 763 Bytes
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
#pragma once
#include <vector>
#include <array>
template <typename T, typename ...Args>
struct MonadDetails<std::vector, T, Args...>
{
static auto pure(T t) -> std::vector<T, Args...>
{
return std::vector<T, Args...>({t});
}
// TODO: Find a way to construct a vector<O> with custom allocator
template <typename O, typename F>
requires CallableR<std::vector<O>, F, T>
static auto bind(std::vector<T, Args...> m, F f) -> std::vector<O>
{
std::vector<O> result;
result.reserve(m.size());
for (auto& t: m)
{
std::vector<O> mapped = std::invoke(f, t);
result.insert(std::end(result), std::begin(mapped), std::end(mapped));
}
return result;
}
};