38#include <gtest/gtest.h>
73 size_t size() const noexcept {
return data.size(); }
123 if (x > 3)
return false;
144template <
class C,
class Op>
145concept TraversesWith =
requires(C & c, Op & op) { c.template traverse<Op>(op); };
147template <
class C,
class Op>
150template <
class C,
class Op>
151concept TestsAllWith =
requires(C & c, Op & op) { c.template all<Op>(op); };
173 EXPECT_TRUE(v.traverse([] (
int & x) { x *= 2; return true; }));
177 EXPECT_TRUE(cv.traverse([&
sum] (
const int & x) { sum += x; return true; }));
180 EXPECT_TRUE(cv.traverse(positive));
181 EXPECT_TRUE(cv.all(positive));
214 EXPECT_TRUE(v.
all([](
int x) { return x % 2 == 0; }));
215 EXPECT_FALSE(v.
all([](
int x) { return x > 5; }));
222 EXPECT_TRUE(v.
all([](
int) { return false; }));
229 EXPECT_TRUE(v.
exists([](
int x) { return x % 2 == 0; }));
230 EXPECT_FALSE(v.
exists([](
int x) { return x > 100; }));
236 EXPECT_FALSE(v.
exists([](
int) { return true; }));
243 auto squared = v.
maps<
int>([](
int x) {
return x * x; });
245 EXPECT_EQ(squared.size(), 3);
249 squared.for_each([&](
int x) { EXPECT_EQ(x,
expected[i++]); });
256 auto strs = v.
maps<
string>([](
int x) {
return to_string(x); });
258 EXPECT_EQ(strs.size(), 3);
260 string expected[] = {
"1",
"2",
"3"};
262 strs.for_each([&](
const string& s) { EXPECT_EQ(s,
expected[i++]); });
274 struct Counted_From_Int
276 static inline int built = 0;
278 Counted_From_Int(
const int x) : v(x) { ++built; }
279 operator int ()
const {
return v; }
291 explicit Feet(
const Meters &
m) : v(
m.v * 3.28084) {}
294 struct Copy_May_Throw
296 static inline bool fail =
false;
298 Copy_May_Throw() =
default;
299 Copy_May_Throw(
const int x) : v(x) {}
300 Copy_May_Throw(
const Copy_May_Throw & c) : v(c.v)
303 throw std::runtime_error(
"the copy fails");
305 Copy_May_Throw & operator = (
const Copy_May_Throw &) =
default;
311 static inline int copies = 0, moves = 0;
313 Counted_Item() =
default;
314 Counted_Item(
const int x) : v(x) {}
315 Counted_Item(
const Counted_Item & c) : v(c.v) { ++copies; }
316 Counted_Item(Counted_Item && c) noexcept : v(c.v) { ++moves; }
317 Counted_Item & operator = (
const Counted_Item &) =
default;
323 static inline int copies = 0;
325 Counted_Copy() =
default;
326 Counted_Copy(
const int x) : v(x) {}
327 Counted_Copy(
const Counted_Copy & c) : v(c.v) { ++copies; }
328 Counted_Copy & operator = (
const Counted_Copy &) =
default;
332 template <
typename T>
336 void append(
T && item) { items.
append(std::move(item)); }
339 template <
class C,
class R>
340 concept Maps_To =
requires (
const C & c) { c.template maps<R>(); };
356 EXPECT_EQ(
copy, build_dynlist<int>(3, 1, 2));
364 Counted_From_Int::built = 0;
366 EXPECT_EQ(Counted_From_Int::built, 3);
367 EXPECT_EQ(counted.
maps<
int>([] (
const Counted_From_Int & c) { return c.v; }), build_dynlist<int>(3, 1, 2));
372 EXPECT_EQ(big.
maps<
double>(), build_dynlist<double>(9223372036854775808.0, 5.0, -7.0));
375 EXPECT_EQ(halves.
maps<
int>(), build_dynlist<int>(3, 0));
379 EXPECT_EQ(feet.
maps<
double>([] (
const Feet & f) { return f.v; }), build_dynlist<double>(3.28084, 6.56168));
389 for (
int i = 0; i < 5; ++i)
391 v.
append(Counted_Item(i));
392 w.append(Counted_Copy(i));
395 Counted_Item::copies = Counted_Item::moves = 0;
397 EXPECT_EQ(Counted_Item::copies, 5);
398 EXPECT_EQ(Counted_Item::moves, 0);
399 EXPECT_EQ(items.
maps<
int>([] (
const Counted_Item & c) { return c.v; }), build_dynlist<int>(0, 1, 2, 3, 4));
401 Counted_Item::copies = Counted_Item::moves = 0;
402 EXPECT_EQ(v.
maps<Counted_Item>().size(), 5u);
403 EXPECT_EQ(Counted_Item::copies, 5);
404 EXPECT_EQ(Counted_Item::moves, 0);
406 Counted_Copy::copies = 0;
408 EXPECT_EQ(Counted_Copy::copies, 5);
409 EXPECT_EQ(copies.
maps<
int>([] (
const Counted_Copy & c) { return c.v; }), build_dynlist<int>(0, 1, 2, 3, 4));
418 const Only_Rvalues<int> same = v.
maps<void, Only_Rvalues>();
419 EXPECT_EQ(same.items, build_dynlist<int>(3, 1, 2));
420 const Only_Rvalues<int> named = v.
maps<int, Only_Rvalues>();
421 EXPECT_EQ(named.items, build_dynlist<int>(3, 1, 2));
422 const Only_Rvalues<double> wide = v.
maps<double, Only_Rvalues>();
423 EXPECT_EQ(wide.items, build_dynlist<double>(3.0, 1.0, 2.0));
426 for (
int i = 0; i < 5; ++i)
427 items.
append(Counted_Item(i));
428 Counted_Item::copies = Counted_Item::moves = 0;
429 const Only_Rvalues<Counted_Item> moved = items.
maps<void, Only_Rvalues>();
430 EXPECT_EQ(Counted_Item::copies, 5);
431 EXPECT_EQ(Counted_Item::moves, 5);
432 EXPECT_EQ(moved.items.size(), 5u);
438 for (
int i = 0; i < 5; ++i)
439 v.
append(Copy_May_Throw(i));
441 Copy_May_Throw::fail =
true;
442 EXPECT_THROW((
void) v.
maps(), std::runtime_error);
443 EXPECT_THROW((
void) v.
maps<Copy_May_Throw>(), std::runtime_error);
444 Copy_May_Throw::fail =
false;
445 EXPECT_EQ(v.
maps().size(), 5u);
452 auto evens = v.
filter([](
int x) {
return x % 2 == 0; });
454 EXPECT_EQ(evens.size(), 3);
458 evens.for_each([&](
int x) { EXPECT_EQ(x,
expected[i++]); });
465 auto evens = v.
filter([](
int x) {
return x % 2 == 0; });
466 EXPECT_TRUE(evens.is_empty());
473 int sum = v.
foldl<
int>(0, [](
int acc,
int x) {
return acc + x; });
476 int product = v.
foldl<
int>(1, [](
int acc,
int x) {
return acc * x; });
484 int result = v.
foldl<
int>(42, [](
int acc,
int x) {
return acc + x; });
485 EXPECT_EQ(result, 42);
492 auto [evens, odds] = v.
partition([](
int x) {
return x % 2 == 0; });
494 EXPECT_EQ(evens.size(), 3);
495 EXPECT_EQ(odds.size(), 3);
497 int expected_evens[] = {2, 4, 6};
498 int expected_odds[] = {1, 3, 5};
501 evens.for_each([&](
int x) { EXPECT_EQ(x, expected_evens[i++]); });
504 odds.for_each([&](
int x) { EXPECT_EQ(x, expected_odds[i++]); });
513 EXPECT_EQ(empty.
length(), 0);
520 auto reversed = v.
rev();
522 EXPECT_EQ(reversed.size(), 5);
526 reversed.for_each([&](
int x) { EXPECT_EQ(x,
expected[i++]); });
533 auto first3 = v.
take(3);
534 EXPECT_EQ(first3.size(), 3);
538 first3.for_each([&](
int x) { EXPECT_EQ(x,
expected[i++]); });
541 EXPECT_EQ(
all.size(), 5);
548 auto last3 = v.
drop(2);
549 EXPECT_EQ(last3.size(), 3);
553 last3.for_each([&](
int x) { EXPECT_EQ(x,
expected[i++]); });
555 auto empty = v.
drop(100);
556 EXPECT_TRUE(empty.is_empty());
568 EXPECT_EQ(v.
nth(0), 10);
569 EXPECT_EQ(v.
nth(2), 30);
570 EXPECT_EQ(v.
nth(4), 50);
572 EXPECT_THROW(v.
nth(5), std::out_of_range);
573 EXPECT_THROW(v.
nth(100), std::out_of_range);
580 constexpr size_t largest = std::numeric_limits<size_t>::max();
582 EXPECT_THROW((
void) empty.
nth(largest), std::out_of_range);
583 EXPECT_THROW((
void) empty.
nth(0), std::out_of_range);
586 EXPECT_THROW((
void) v.
nth(largest), std::out_of_range);
593 EXPECT_EQ(v.
nth_ne(0), 10);
594 EXPECT_EQ(v.
nth_ne(1), 20);
595 EXPECT_EQ(v.
nth_ne(2), 30);
603 EXPECT_EQ(v.
nth(1), 25);
610 int* p = v.
find_ptr([](
int x) {
return x == 3; });
611 ASSERT_NE(p,
nullptr);
614 int* not_found = v.
find_ptr([](
int x) {
return x == 100; });
615 EXPECT_EQ(not_found,
nullptr);
622 int* p = v.
find_ptr([](
int x) {
return x == 3; });
623 ASSERT_NE(p,
nullptr);
626 EXPECT_EQ(v.
nth(2), 30);
633 auto [found, item] = v.
find_item([](
int x) {
return x > 3; });
637 auto [not_found, default_val] = v.
find_item([](
int x) {
return x > 100; });
638 EXPECT_FALSE(not_found);
651 EXPECT_EQ(
k.size(), 3);
658 auto items = v.
items();
659 EXPECT_EQ(items.
size(), 3);
672 auto evens = v.
filter([](
int x) {
return x % 2 == 0; });
673 auto squared = evens.
maps<
int>([](
int x) {
return x * x; });
675 EXPECT_EQ(squared.size(), 3);
679 squared.for_each([&](
int x) { EXPECT_EQ(x,
expected[i++]); });
687 auto squared = v.
maps<
int>([](
int x) {
return x * x; });
688 int sum = squared.foldl<
int>(0, [](
int acc,
int x) {
return acc + x; });
690 EXPECT_EQ(
sum, 1 + 4 + 9 + 16 + 25);
704TEST(ComplexTypes, StructOperations)
707 people.
append({
"Alice", 30});
708 people.
append({
"Bob", 25});
709 people.
append({
"Charlie", 35});
715 ASSERT_NE(oldest,
nullptr);
716 EXPECT_EQ(oldest->
name,
"Charlie");
719 auto ages = people.
maps<
int>([](
const Person& p) {
return p.
age; });
720 int sum = ages.foldl<
int>(0, [](
int acc,
int a) {
return acc + a; });
724 auto over27 = people.
filter([](
const Person& p) {
return p.
age > 27; });
725 EXPECT_EQ(over27.size(), 2);
736 EXPECT_EQ(v.
sum(), 15);
737 EXPECT_EQ(v.
sum(10), 25);
743 EXPECT_EQ(v.
sum(), 0);
744 EXPECT_EQ(v.
sum(100), 100);
750 EXPECT_EQ(v.
sum(),
"Hello World");
751 EXPECT_EQ(v.
sum(
string(
"Prefix: ")),
"Prefix: Hello World");
780 EXPECT_EQ(v.
min(),
nullptr);
786 ASSERT_NE(v.
min(),
nullptr);
787 EXPECT_EQ(*v.
min(), 42);
802 EXPECT_EQ(v.
max(),
nullptr);
808 ASSERT_NE(v.
max(),
nullptr);
809 EXPECT_EQ(*v.
max(), 42);
816 const string* shortest = v.
min_by([](
const string& a,
const string& b) {
817 return a.length() < b.length();
820 ASSERT_NE(shortest,
nullptr);
821 EXPECT_EQ(*shortest,
"a");
828 const string* longest = v.
max_by([](
const string& a,
const string& b) {
829 return a.length() < b.length();
832 ASSERT_NE(longest,
nullptr);
833 EXPECT_EQ(*longest,
"banana");
840 EXPECT_EQ(*v.
min(), -10);
841 EXPECT_EQ(*v.
max(), 7);
880 EXPECT_TRUE(v.
none([](
int x) { return x % 2 != 0; }));
881 EXPECT_FALSE(v.
none([](
int x) { return x > 5; }));
887 EXPECT_TRUE(v.
none([](
int) { return true; }));
894 auto is_odd = [](
int x) {
return x % 2 != 0; };
902 EXPECT_EQ(v.
count_if([](
int x) { return x % 2 == 0; }), 5);
903 EXPECT_EQ(v.
count_if([](
int x) { return x > 5; }), 5);
904 EXPECT_EQ(v.
count_if([](
int x) { return x > 100; }), 0);
905 EXPECT_EQ(v.
count_if([](
int) { return true; }), 10);
911 EXPECT_EQ(v.
count_if([](
int) { return true; }), 0);
923 const int* ptr = v.
first();
924 ASSERT_NE(ptr,
nullptr);
931 EXPECT_EQ(v.
first(),
nullptr);
947 const int* ptr = v.
last();
948 ASSERT_NE(ptr,
nullptr);
955 EXPECT_EQ(v.
last(),
nullptr);
964 EXPECT_EQ(empty.
last_or(-1), -1);
971 EXPECT_EQ(*v.
first(), 42);
972 EXPECT_EQ(*v.
last(), 42);
987 EXPECT_EQ(enumerated.size(), 3);
989 size_t expected_idx = 0;
990 string expected_vals[] = {
"a",
"b",
"c"};
991 enumerated.for_each([&](
const std::pair<size_t, string>& p) {
992 EXPECT_EQ(p.first, expected_idx);
993 EXPECT_EQ(p.second, expected_vals[expected_idx]);
1002 EXPECT_TRUE(enumerated.is_empty());
1009 EXPECT_EQ(v.
find_index([](
int x) { return x == 30; }), 2);
1010 EXPECT_EQ(v.
find_index([](
int x) { return x > 35; }), 3);
1011 EXPECT_EQ(v.
find_index([](
int x) { return x > 100; }), v.
size());
1017 EXPECT_EQ(v.
find_index([](
int) { return true; }), 0u);
1034 EXPECT_EQ(v.
index_of(
"banana"), 1);
1048 auto evens = v.
filter([](
int x) {
return x % 2 == 0; });
1049 int sum = evens.foldl<
int>(0, [](
int acc,
int x) {
return acc + x; });
1050 EXPECT_EQ(
sum, 2 + 4 + 6 + 8 + 10);
1053 EXPECT_EQ(v.
sum(), 55);
1056TEST(ChainedOps, MinMaxOnMixinVector)
1060 EXPECT_EQ(*v.
min(), 1);
1061 EXPECT_EQ(*v.
max(), 9);
1064TEST(ChainedOps, EnumerateThenCountElements)
1069 EXPECT_EQ(enumerated.size(), 4);
1073 int even_count = enumerated.foldl<
int>(0, [](
int acc,
const std::pair<size_t, string>& p) {
1074 return acc + (p.first % 2 == 0 ? 1 : 0);
1076 EXPECT_EQ(even_count, 2);
1086 constexpr size_t N = 10000;
1089 for (
size_t i = 0; i <
N; ++i)
1093 size_t sum = v.
foldl<
size_t>(0, [](
size_t acc,
size_t x) {
return acc + x; });
1094 EXPECT_EQ(
sum,
N * (
N - 1) / 2);
1097 EXPECT_EQ(v.
sum(),
N * (
N - 1) / 2);
1100 auto evens = v.
filter([](
size_t x) {
return x % 2 == 0; });
1101 EXPECT_EQ(evens.size(),
N / 2);
1104 EXPECT_EQ(v.
count_if([](
size_t x) { return x % 2 == 0; }),
N / 2);
1107 EXPECT_TRUE(v.
all([](
size_t x) { return x < N; }));
1110 EXPECT_EQ(*v.
min(), 0);
1111 EXPECT_EQ(*v.
max(),
N - 1);
1118 EXPECT_EQ(*v.
first(), 0);
1119 EXPECT_EQ(*v.
last(),
N - 1);
1124 constexpr size_t N = 1000;
1127 for (
size_t i = 0; i <
N; ++i)
1128 v.
append(
static_cast<int>(i * 2));
1131 EXPECT_EQ(enumerated.size(),
N);
1135 enumerated.for_each([&idx](
const std::pair<size_t, int>& p) {
1136 EXPECT_EQ(p.first, idx);
1137 EXPECT_EQ(p.second,
static_cast<int>(idx * 2));
1154TEST(ConstraintTest, MethodsWithoutConstraintsWork)
1162 EXPECT_EQ(v.
length(), 3);
1163 EXPECT_NE(v.
first(),
nullptr);
1164 EXPECT_NE(v.
last(),
nullptr);
1165 EXPECT_EQ(v.
first()->value, 1);
1166 EXPECT_EQ(v.
last()->value, 3);
1169 EXPECT_EQ(enumerated.size(), 3);
1193TEST(ConstraintTest, EqualityOnlyType)
1217TEST(ConstraintTest, LessThanOnlyType)
1225 EXPECT_EQ(v.
min()->value, 1);
1226 EXPECT_EQ(v.
max()->value, 3);
1243 EXPECT_EQ(u.size(), 4);
1247 u.for_each([&](
int x) { EXPECT_EQ(x,
expected[i++]); });
1254 EXPECT_TRUE(u.is_empty());
1261 EXPECT_EQ(u.size(), 1);
1265 u.traverse([&first_val](
int x) { first_val = x;
return false; });
1266 EXPECT_EQ(first_val, 42);
1273 EXPECT_EQ(u.size(), 5);
1280 auto u = v.
unique_by([](
const string& a,
const string& b) {
1284 EXPECT_EQ(u.size(), 3);
1292 EXPECT_EQ(i.size(), 5);
1296 i.for_each([&](
int x) { EXPECT_EQ(x,
expected[idx++]); });
1303 EXPECT_TRUE(i.is_empty());
1310 EXPECT_EQ(i.size(), 1);
1314 i.traverse([&first_val](
int x) { first_val = x;
return false; });
1315 EXPECT_EQ(first_val, 42);
1322 EXPECT_EQ(i.size(), 5);
1334 auto chunks = v.
chunk(2);
1335 EXPECT_EQ(chunks.size(), 3);
1338 size_t first_chunk_size = 0;
1339 chunks.traverse([&first_chunk_size](
const auto& c) {
1340 first_chunk_size = c.size();
1343 EXPECT_EQ(first_chunk_size, 2);
1350 auto chunks = v.
chunk(2);
1351 EXPECT_EQ(chunks.size(), 3);
1357 auto chunks = v.
chunk(2);
1358 EXPECT_TRUE(chunks.is_empty());
1364 auto chunks = v.
chunk(0);
1365 EXPECT_TRUE(chunks.is_empty());
1371 auto chunks = v.
chunk(10);
1372 EXPECT_EQ(chunks.size(), 1);
1380 EXPECT_EQ(windows.size(), 3);
1383 windows.for_each([](
const auto&
w) { EXPECT_EQ(
w.size(), 3); });
1390 auto windows = v.
sliding(2, 2);
1391 EXPECT_EQ(windows.size(), 3);
1398 EXPECT_TRUE(windows.is_empty());
1405 EXPECT_TRUE(windows.is_empty());
1412 EXPECT_TRUE(windows.is_empty());
1425 EXPECT_EQ(vec.size(), 5);
1426 EXPECT_EQ(vec[0], 1);
1427 EXPECT_EQ(vec[4], 5);
1434 EXPECT_TRUE(vec.empty());
1442 EXPECT_EQ(list.
size(), 5);
1446 EXPECT_EQ(it.get_curr(), 1);
1448 EXPECT_EQ(it.get_curr(), 2);
1467 EXPECT_EQ(vec.size(), list.
size());
1471 EXPECT_EQ(x, vec[i++]);
1479 string s = v.
join(
string(
", "));
1480 EXPECT_EQ(s,
"1, 2, 3");
1486 string s = v.
join(
string(
"-"));
1493 string s = v.
join(
string(
", "));
1502 EXPECT_EQ(s,
"a-b-c");
1526 EXPECT_EQ(zipped.size(), 3);
1529 auto it = zipped.get_it();
1530 EXPECT_EQ(it.get_curr().first, 1);
1531 EXPECT_EQ(it.get_curr().second,
"a");
1540 EXPECT_EQ(zipped.size(), 2);
1549 EXPECT_TRUE(zipped.is_empty());
1558 EXPECT_TRUE(zipped.is_empty());
1570 auto unique_result = v.
unique();
1571 EXPECT_EQ(unique_result.size(), 3);
1576 unique_result.for_each([&](
int x) { EXPECT_EQ(x,
expected[idx++]); });
1583 auto chunks = v.
chunk(2);
1588 total += chunk.
foldl<
int>(0, [](
int acc,
int x) {
return acc + x; });
1590 EXPECT_EQ(total, 21);
1598TEST(DynListIntegration, ExistingMethodsWork)
1602 for (
int i = 1; i <= 5; ++i)
1606 int sum = list.
foldl<
int>(0, [](
int acc,
int x) {
return acc + x; });
1610 auto evens = list.
filter([](
int x) {
return x % 2 == 0; });
1611 EXPECT_EQ(evens.size(), 2);
1614 EXPECT_TRUE(list.
all([](
int x) { return x <= 5; }));
1617 EXPECT_TRUE(list.
exists([](
int x) { return x == 3; }));
1652 EXPECT_FALSE(a2.equal_to(a3));
1653 EXPECT_FALSE(a3 == a2);
1654 EXPECT_TRUE(a3 != a2);
1660 EXPECT_FALSE(d2.equal_to(d3));
1661 EXPECT_FALSE(d3 == d2);
1662 EXPECT_TRUE(d3 != d2);
1670 EXPECT_TRUE(a == a);
1671 EXPECT_FALSE(a != a);
1675 EXPECT_TRUE(d == d);
1676 EXPECT_FALSE(d != d);
1686 EXPECT_FALSE(a1 == a2);
1687 EXPECT_TRUE(a1 != a2);
1693 EXPECT_FALSE(d1 == d2);
1694 EXPECT_TRUE(d1 != d2);
1704 EXPECT_FALSE(a1 == a2);
1705 EXPECT_TRUE(a1 != a2);
1711 EXPECT_FALSE(d1 == d2);
1712 EXPECT_TRUE(d1 != d2);
1722 EXPECT_TRUE(a1 == a2);
1723 EXPECT_FALSE(a1 != a2);
1729 EXPECT_TRUE(d1 == d2);
1730 EXPECT_FALSE(d1 != d2);
1737 EXPECT_TRUE(a1 == a2);
1738 EXPECT_FALSE(a1 != a2);
1742 EXPECT_TRUE(d1 == d2);
1743 EXPECT_FALSE(d1 != d2);
1756 EXPECT_TRUE(a1 != a3);
1763 EXPECT_TRUE(d1 == d2);
1764 EXPECT_FALSE(d1 == d3);
1769 constexpr size_t N = 10000;
1773 for (
size_t i = 0; i <
N; ++i)
1781 EXPECT_TRUE(a1 == a2);
1782 EXPECT_TRUE(d1 == d2);
1785 EXPECT_FALSE(a1 != a2);
1786 EXPECT_FALSE(d1 != d2);
1792 EXPECT_FALSE(a1 == a2);
1793 EXPECT_FALSE(d1 == d2);
1796 EXPECT_TRUE(a1 != a2);
1797 EXPECT_TRUE(d1 != d2);
CRTP Mixins for container functionality (DRY principle).
static DynArray< int > make_dynarray(std::initializer_list< int > vals)
static Array< int > make_array(std::initializer_list< int > vals)
Simple dynamic array with automatic resizing and functional operations.
T & append(const T &data)
Append a copy of data
T & append()
Allocate a new entry to the end of array.
Doubly-linked list (defined in tpl_dynList.H).
T & append(const T &item)
size_t size() const noexcept
Return the number of items of the list, in constant time.
CRTP Mixin providing functional programming operations.
size_t count_if(Predicate pred) const
Count elements satisfying a predicate.
Container< Type > drop(const size_t n) const
Skip the first n elements.
Container< std::pair< size_t, Type > > enumerate() const
Enumerate elements with their indices.
Container< Container< Type > > chunk(size_t n) const
Split into chunks of fixed size.
DynListType to_dynlist() const
Convert container to DynList.
std::pair< DynList< Type >, DynList< Type > > partition(Operation &op) const
Partition elements by a predicate.
auto mutable_for_each(Operation &operation) -> decltype(self())
Apply an operation to each element (mutable).
const Type * min_by(Compare cmp) const
Find the minimum element using a custom comparator.
const Type * max() const
Find the maximum element.
Container< Type > unique_by(EqPred eq) const
Remove consecutive duplicates using a custom equality predicate.
bool none(Predicate &pred) const
Check if no element satisfies a predicate.
Container< Type > rev() const
Create a reversed copy.
Acc foldl(const Acc &init, std::function< Acc(const Acc &, const Type &)> operation) const
Left fold (reduce) with initial value.
bool exists(Operation &operation) const
Test if any element satisfies a predicate.
Container< Container< Type > > sliding(size_t size, size_t step=1) const
Create sliding windows of fixed size.
Container< Type > take(const size_t n) const
Take the first n elements.
std::string join_str(const std::string &sep=", ") const
Join string elements with separator.
Container< Type > unique() const
Remove consecutive duplicate elements.
const Type * first() const
Get the first element.
Container< std::pair< Type, typename Other::Item_Type > > zip_with(const Other &other) const
Zip with another container.
Type last_or(const Type &default_val) const
Get the last element or a default value.
Container< concepts_detail::map_result_t< R, Operation &, Type > > maps(Operation &operation) const
auto for_each(Operation &operation) const -> decltype(self())
Apply an operation to each element (read-only).
bool has_value(const Type &val) const
Check if container has a value.
StringType join(const StringType &sep=StringType{", "}) const
Join elements into a string with separator.
size_t index_of(const Type &val) const
Find the index of a specific value.
Type product(const Type &init) const
Compute the product of all elements.
bool all(Operation &operation) const
Test if all elements satisfy a predicate.
size_t length() const noexcept
Count the number of elements.
Type sum(const Type &init=Type{}) const
Compute the sum of all elements.
size_t find_index(Predicate pred) const
Find the index of the first element satisfying a predicate.
std::vector< Type > to_vector() const
Convert to std::vector.
const Type * max_by(Compare cmp) const
Find the maximum element using a custom comparator.
Container< Type > intersperse(const Type &sep) const
Intersperse a separator between elements.
Type first_or(const Type &default_val) const
Get the first element or a default value.
DynList< Type > filter(Operation &operation) const
Filter elements by a predicate.
const Type * last() const
Get the last element.
const Type * min() const
Find the minimum element.
constexpr bool is_empty() const noexcept
CRTP Mixin for extracting keys from set-like containers.
Container< Type > items() const
Alias for keys().
Container< Type > keys() const
Extract all keys as a list.
CRTP Mixin providing element location operations.
std::tuple< bool, Type > find_item(Operation &operation)
Find element with success flag.
Type * find_ptr(Operation &operation)
Find the first element satisfying a predicate.
Type & nth(const size_t n)
Access the n-th element (bounds-checked).
Type & nth_ne(const size_t n) noexcept
Access the n-th element (unchecked).
Number Theoretic Transform over Z / MOD Z.
CRTP Mixin providing traversal operations.
bool traverse(Operation &operation) const
Traverse all elements, applying an operation to each.
Minimal std::expected-style result type for C++20.
Mixin providing equality comparison for sequence containers.
bool equal_to(const Container &r) const
Equality test between this and r.
Aleph::DynList< Aleph::dry_detail::map_result_t< R, Operation &, T > > maps(Operation &op) const
bool exists(Operation &op) const
Test for existence in the container of an element satisfying a criterion.
Aleph::DynList< T > filter(Operation &operation) const
Filter the elements of a container according to a matching criterion.
bool all(Operation &operation) const
Check if all the elements of the container satisfy a condition.
Acc foldl(const Acc &init, Op &op) const
Fold the elements of the container to a specific result.
void for_each(Operation &operation) const
Traverse all the container and performs an operation on each element.
auto get_it()
Return a properly initialized iterator positioned at the first item on the container.
Iterator(const MixinVector &c)
const MixinVector * container
bool has_curr() const noexcept
Simple test container using std::vector internally but with Aleph mixins.
void insert(const T &item)
bool operator==(const MixinVector &other) const
void append(const T &item)
MixinVector(std::initializer_list< T > init)
size_t size() const noexcept
bool is_empty() const noexcept
Singly linked list implementations with head-tail access.
Main namespace for Aleph-w library functions.
std::string tolower(const char *str)
Convert a C std::string to lower-case.
bool completed() const noexcept
Return true if all underlying iterators are finished.
const Container::Item_Type * max_ptr(const Container &container, Cmp cmp=Cmp())
Find the maximum element in a container.
Itor2 copy(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg)
Copy elements from one range to another.
bool all(Container &container, Operation &operation)
Return true if all elements satisfy a predicate.
std::decay_t< typename HeadC::Item_Type > T
T product(const Container &container, const T &init=T{1})
Compute product of all elements.
std::string to_string(const time_t t, const std::string &format)
Format a time_t value into a string using format.
static std::atomic< bool > init
const Container::Item_Type * min_ptr(const Container &container, Cmp cmp=Cmp())
Find the minimum element in a container.
DynList< T > maps(const C &c, Op op)
Classic map operation.
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
Represents a missing value.
bool operator==(const EqOnlyType &other) const
bool operator<(const LtOnlyType &other) const
bool operator()(const int &x) const
bool operator()(int &x) const
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)
Dynamic array container with automatic resizing.
Lazy and scalable dynamic array implementation.