-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathprojection.hpp
45 lines (35 loc) · 879 Bytes
/
projection.hpp
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
#pragma once
#include "ra/operation.hpp"
#include "sql/row.hpp"
namespace ra
{
template <typename Output, typename Input>
class projection : public ra::unary<Input>
{
using input_type = typename ra::unary<Input>::input_type;
public:
using output_type = Output;
static auto&& next()
{
fold<output_type>(output_row, Input::next());
return std::move(output_row);
}
private:
template <typename Dest>
static inline constexpr void fold(Dest& dest, input_type const& src)
{
if constexpr (Dest::depth == 0)
{
return;
}
else
{
dest.head() = sql::get<Dest::column::name>(src);
fold<typename Dest::next>(dest.tail(), src);
}
}
static output_type output_row;
};
template <typename Output, typename Input>
typename projection<Output, Input>::output_type projection<Output, Input>::output_row{};
} // namespace ra