32 using arr = std::array<int, 8>;
33 const arr input = {2, 3, 5, 7, 11, 13, 17, 19};
34 const arr input2 = {1, 1, 1, 1, 1, 1, 1, 1};
35 const auto unary_f = [](
int x) {
return x * x; };
36 const auto binary_f = [](
int a,
int b) {
return a - b; };
37 const arr squared = {4, 9, 25, 49, 121, 169, 289, 361};
38 const arr pminusone = {1, 2, 4, 6, 10, 12, 16, 18};
40 const auto equal = [](
auto a,
auto b) {
41 return std::equal(std::begin(
a), std::end(
a), std::begin(b), std::end(b));
43 [[gnu::unused]]
auto print_arr = [&](
auto c) {
44 for (
const auto& v : c) {
45 std::cout << v <<
", ";
50 SECTION(
"unary dynamic build") {
57 REQUIRE(
equal(squared, built));
59 SECTION(
"binary dynamic build") {
66 REQUIRE(
equal(pminusone, built));
68 SECTION(
"unary array build") {
73 REQUIRE(
equal(squared, built));
75 SECTION(
"binary array build") {
78 auto built =
std::transform(input.begin(), input.end(), input2.begin(),
81 REQUIRE(
equal(pminusone, built));
83 const arr
iota = {0, 1, 2, 3, 4, 5, 6, 7};
84 SECTION(
"dynamic generator build") {
88 [x = 0]()
mutable {
return x++; })
92 SECTION(
"array generator build") {
96 [x = 0]()
mutable {
return x++; })
107 SECTION(
"dynamic buildiota") {
111 = kblib::construct_from_range<std::vector<int>>(
kblib::range(0, 8));
114 SECTION(
"array buildiota") {
122 using arr = std::array<int, 8>;
123 KBLIB_UNUSED const arr input = {2, 3, 5, 7, 11, 13, 17, 19};
Provides general-purpose algorithms, similar to the <algorithms> header.
Provides generic operations for containers, as well as kblib::stack.
constexpr auto a(const std::initializer_list< T > &a) -> auto
Index an array literal without naming its type.
constexpr auto generate(OutputIt first, EndIt last, Generator g) noexcept(noexcept(*++first=g())) -> OutputIt
Like std::generate except that it returns the output iterator at the end. It also allows for a sentin...
constexpr auto iota(ForwardIt first, ForwardIt last, T value) noexcept(noexcept(*first++=value) and noexcept(++value)) -> void
constexpr auto generate_n(OutputIt first, Size count, Generator g) noexcept(noexcept(*first++=g())) -> OutputIt
Like std::generate_n except that it is constexpr.
constexpr auto range(Value min, Value max, Delta step=0) -> range_t< Value, Delta >
Constructs a range from beginning, end, and step amount. The range is half-open, that is min is in th...
constexpr struct kblib::build_end_t build_end
constexpr auto try_get(Map &map, Key &&key) -> copy_const_t< Map, typename Map::mapped_type > *
constexpr auto equal(InputIt1 first1, InputIt1 last1, InputIt2 first2) -> bool
constexpr auto transform(InputIt first, EndIt last, OutputIt d_first, UnaryOperation unary_op) -> OutputIt
transform applies the given function to a range and stores the result in another range,...
#define KBLIB_UNUSED
This internal macro is used to provide a fallback for [[maybe_unused]] in C++14.