utempl/examples/src/pipe.cpp

21 lines
524 B
C++
Raw Normal View History

2024-03-28 19:19:56 +00:00
#include <utempl/utils.hpp>
2024-04-12 12:16:37 +00:00
struct Container {
float data{};
};
2024-03-28 19:19:56 +00:00
auto main() -> int {
using namespace utempl;
2024-04-12 12:16:37 +00:00
constexpr auto value = Tuple{1, 2, 3, 4, 5, 6}
2024-03-28 19:19:56 +00:00
| Take<5>()
2024-04-12 12:16:37 +00:00
| Map([](int arg) {return arg + 1;})
2024-03-28 19:19:56 +00:00
| Map([](int arg) -> float {return arg;})
2024-04-12 12:16:37 +00:00
| Map([](float arg) -> Container {return {.data = arg};})
2024-03-28 19:19:56 +00:00
| Reverse()
2024-04-12 12:16:37 +00:00
| Take<3>()
| Reduce(0.f, [](auto accumulator, Container arg) -> float {
return accumulator + arg.data;
}); // Lazy evavalue
static_assert(value == 15.0f);
2024-03-28 19:19:56 +00:00
};