Console Library 8.0.0
A header-only library that makes C++ simple
Loading...
Searching...
No Matches
gen.h
Go to the documentation of this file.
1
9
10/*
11Copyright (c) 2026 MrXie1109
12
13Permission is hereby granted, free of charge, to any person obtaining a copy
14of this software and associated documentation files (the "Software"), to deal
15in the Software without restriction, including without limitation the rights
16to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17copies of the Software, and to permit persons to whom the Software is
18furnished to do so, subject to the following conditions:
19
20The above copyright notice and this permission notice shall be included in all
21copies or substantial portions of the Software.
22
23THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29SOFTWARE.
30*/
31
32#pragma once
33#include <cmath>
34#include <cstdlib>
35#include <iterator>
36#include <type_traits>
37#include <utility>
38#include <vector>
39
40#include "../core/csexc.h"
41#include "../text/repr.h"
42#include "./iter.h"
43
44namespace console {
50 template <class Derived, class T>
51 class Generator {
52 public:
56 class iterator {
57 Derived d;
58
59 public:
60 using value_type = T;
61 using reference = T;
62 using pointer = void;
63 using difference_type = std::ptrdiff_t;
64 using iterator_category = std::input_iterator_tag;
65
70 iterator(const Derived &d) : d(d) {}
71
78 if (done()) throw StopIteration("StopIteration");
79 return d.current();
80 }
81
87 if (done()) return *this;
88 d.advance();
89 return *this;
90 }
91
96 const iterator operator++(int) {
97 if (done()) return *this;
98 auto old = *this;
99 d.advance();
100 return old;
101 }
102
107 bool operator==(const iterator &) { return d.done(); }
108
113 bool operator!=(const iterator &) { return !d.done(); }
114
120 T next() {
121 if (done()) throw StopIteration("StopIteration");
122 auto current = d.current();
123 d.advance();
124 return current;
125 }
126
131 bool done() { return d.done(); }
132 };
133
138 iterator iter() const {
139 return iterator(static_cast<const Derived &>(*this));
140 }
141
146 iterator begin() const { return iter(); }
147
152 iterator end() const { return iter(); }
153
154 typedef T value_type;
155
160 bool done() { return static_cast<Derived &>(*this).done(); }
161
166 T current() { return static_cast<Derived &>(*this).current(); }
167
171 void advance() { static_cast<Derived &>(*this).advance(); }
172 };
173
179 template <class Derived, class T>
183
189 template <class Derived, class T>
191 return it.next();
192 }
193
204 template <class Derived,
205 class T,
206 class CharT = char,
207 class Traits = std::char_traits<CharT>>
208 std::basic_ostream<CharT, Traits> &
209 print_generator(std::basic_ostream<CharT, Traits> &os,
210 const Generator<Derived, T> &gen) {
211 os << CharT('[');
212 bool first = true;
213 for (auto it = gen.begin(); it != gen.end(); ++it) {
214 if (!first) {
215 os << CharT(','), os << CharT(' ');
216 }
217 first = false;
218 repr(*it, os);
219 }
220 os << CharT(']');
221 return os;
222 }
223
227 template <class Derived,
228 class T,
229 class CharT = char,
230 class Traits = std::char_traits<CharT>>
231 std::basic_ostream<CharT, Traits> &
232 operator<<(std::basic_ostream<CharT, Traits> &os,
233 const Generator<Derived, T> &gen) {
234 return print_generator(os, gen);
235 }
236
237 namespace gen {
242 template <class Iter>
243 class Views : public Generator<Views<Iter>,
244 typename std::iterator_traits<Iter>::value_type> {
245 Iter curr;
246 Iter end_;
247
248 public:
249 using value_type = typename std::iterator_traits<Iter>::value_type;
250
256 Views(Iter begin, Iter end) : curr(begin), end_(end) {}
257
263 template <class Container>
264 Views(const Container &container) :
265 curr(std::begin(container)), end_(std::end(container)) {}
266
271 bool done() { return curr == end_; }
272
277 value_type current() { return *curr; }
278
282 void advance() {
283 if (curr != end_) ++curr;
284 }
285 };
286
291 template <class T>
292 class List : public Generator<List<T>, T> {
293 std::vector<T> data;
294 size_t idx = 0;
295
296 public:
301 List(std::initializer_list<T> list) : data(list) {}
302
309 template <class Iterator>
310 List(Iterator begin, Iterator end) : data(begin, end) {}
311
317 template <class Container>
318 List(const Container &container) :
319 data(std::begin(container), std::end(container)) {}
320
324 bool done() { return idx >= data.size(); }
325
329 T current() { return data[idx]; }
330
334 void advance() { idx++; }
335 };
336
341 template <class T>
342 class Range : public Generator<Range<T>, T> {
345
346 public:
353 Range(T begin, T end, T step = 1) :
355
360 Range(T end) : start(0), curr(0), end_(end), step(1) {}
361
366 bool done() { return step > 0 ? curr >= end_ : curr <= end_; }
367
372 T current() { return curr; }
373
377 void advance() { curr += step; }
378 };
379
384 template <class T>
385 class Repeat : public Generator<Repeat<T>, T> {
387 size_t count;
388 size_t index = 0;
389
390 public:
396 Repeat(T val, size_t n) : value(val), count(n) {}
397
403 Repeat(T val) : value(val), count(size_t(-1)) {}
404
409 bool done() { return count != size_t(-1) && index >= count; }
410
415 T current() { return value; }
416
420 void advance() { index++; }
421 };
422
427 template <class T>
428 class Cycle : public Generator<Cycle<T>, T> {
429 std::vector<T> data;
430 size_t index = 0;
431
432 public:
437 Cycle(std::initializer_list<T> list) : data(list) {}
438
445 template <class Iterator>
446 Cycle(Iterator begin, Iterator end) : data(begin, end) {}
447
453 template <class Container>
454 Cycle(const Container &container) :
455 data(std::begin(container), std::end(container)) {}
456
461 bool done() { return false; }
462
467 T current() { return data[index % data.size()]; }
468
472 void advance() { index++; }
473 };
474
478 template <class T>
479 class Counter : public Generator<Counter<T>, T> {
482 size_t max_count;
483 size_t count;
484
485 public:
492 Counter(T start = T{0}, T step = T{1}, size_t times = size_t(-1)) :
493 curr(start), step(step), max_count(times), count(0) {}
494
500 bool done() {
501 return max_count != size_t(-1) && count >= max_count;
502 }
503
508 T current() { return curr; }
509
514 void advance() {
515 curr += step;
516 count++;
517 }
518 };
519
525 template <class Gen, class Func>
526 class Map
527 : public Generator<Map<Gen, Func>,
528 typename std::decay<decltype(std::declval<Func>()(
529 std::declval<typename Gen::iterator::value_type>()))>::
530 type> {
531 Gen gen;
532 Func func;
534 typename std::decay<decltype(func(gen.current()))>::type;
535
536 public:
542 Map(Gen g, Func f) : gen(g), func(f) {}
543
548 bool done() { return gen.done(); }
549
554 ResultType current() { return func(gen.current()); }
555
559 void advance() { gen.advance(); }
560 };
561
567 template <class Gen, class Pred>
568 class Filter : public Generator<Filter<Gen, Pred>,
569 typename Gen::iterator::value_type> {
570 Gen gen;
571 Pred pred;
572 bool valid;
574
578 void find_next() {
579 while (!gen.done()) {
580 if (pred(gen.current())) {
581 valid = true;
582 return;
583 }
584 gen.advance();
585 }
586 valid = false;
587 }
588
589 public:
595 Filter(Gen g, Pred p) :
596 gen(g), pred(p), valid(false), initialized(false) {}
597
602 bool done() {
603 if (!initialized) {
604 find_next();
605 initialized = true;
606 }
607 return !valid;
608 }
609
614 auto current() -> decltype(gen.current()) {
615 if (!initialized) {
616 find_next();
617 initialized = true;
618 }
619 return gen.current();
620 }
621
625 void advance() {
626 if (!valid) return;
627 gen.advance();
628 find_next();
629 }
630 };
631
636 template <class Gen>
637 class Take : public Generator<Take<Gen>, typename Gen::value_type> {
638 Gen gen;
639 size_t count;
640 size_t taken = 0;
641
642 public:
648 Take(Gen g, size_t n) : gen(g), count(n) {}
649
654 bool done() { return taken >= count || gen.done(); }
655
660 auto current() -> decltype(gen.current()) { return gen.current(); }
661
665 void advance() {
666 gen.advance();
667 taken++;
668 }
669 };
670
675 template <class Gen>
676 class Drop
677 : public Generator<Drop<Gen>, typename Gen::iterator::value_type> {
678 Gen gen;
679 size_t count;
680 bool droped = false;
681
685 void do_drop() {
686 for (size_t i = 0; i < count && !gen.done(); i++) gen.advance();
687 droped = true;
688 }
689
690 public:
696 Drop(Gen g, size_t n) : gen(g), count(n) {}
697
702 bool done() {
703 if (!droped) do_drop();
704 return gen.done();
705 }
706
711 auto current() -> decltype(gen.current()) {
712 if (!droped) do_drop();
713 return gen.current();
714 }
715
719 void advance() {
720 if (!droped) do_drop();
721 if (!gen.done()) gen.advance();
722 }
723 };
724
729 template <class Gen>
731 : public Generator<Enumerate<Gen>,
732 std::pair<size_t, typename Gen::iterator::value_type>> {
733 Gen gen;
734 size_t index = 0;
735
736 public:
741 Enumerate(Gen g) : gen(g) {}
742
747 bool done() { return gen.done(); }
748
753 auto current() -> decltype(std::make_pair(index, gen.current())) {
754 return std::make_pair(index, gen.current());
755 }
756
760 void advance() {
761 gen.advance();
762 index++;
763 }
764 };
765
770 template <class Func>
771 class Generate : public Generator<Generate<Func>,
772 decltype(std::declval<Func>()())> {
773 Func func;
774 decltype(func()) curr;
775
776 public:
781 Generate(Func f) : func(f), curr(func()) {}
782
787 bool done() { return false; }
788
793 decltype(curr) current() { return curr; }
794
798 void advance() { curr = func(); }
799 };
800
806 template <class Gen1, class Gen2>
807 class Zip : public Generator<Zip<Gen1, Gen2>,
808 std::pair<typename Gen1::value_type,
809 typename Gen2::value_type>> {
810 Gen1 gen1;
811 Gen2 gen2;
812
813 public:
819 Zip(Gen1 g1, Gen2 g2) : gen1(g1), gen2(g2) {}
820
825 bool done() { return gen1.done() || gen2.done(); }
826
831 std::pair<typename Gen1::value_type, typename Gen2::value_type>
833 return std::make_pair(gen1.current(), gen2.current());
834 }
835
839 void advance() {
840 gen1.advance();
841 gen2.advance();
842 }
843 };
844
850 template <class Gen, class Pred>
852 : public Generator<TakeWhile<Gen, Pred>, typename Gen::value_type> {
853 Gen gen;
854 Pred pred;
855 bool stopped = false;
856
857 void try_advance() {
858 if (stopped || gen.done()) return;
859 if (!pred(gen.current())) {
860 stopped = true;
861 }
862 }
863
864 public:
870 TakeWhile(Gen g, Pred p) : gen(g), pred(p) {}
871
876 bool done() { return gen.done() || stopped; }
877
882 auto current() -> decltype(gen.current()) { return gen.current(); }
883
887 void advance() {
888 gen.advance();
889 try_advance();
890 }
891 };
892
898 template <class Gen, class Pred>
900 : public Generator<DropWhile<Gen, Pred>, typename Gen::value_type> {
901 Gen gen;
902 Pred pred;
903 bool droped = false;
904
908 void do_drop() {
909 while (!gen.done() && pred(gen.current())) gen.advance();
910 droped = true;
911 }
912
913 public:
914 DropWhile(Gen g, Pred p) : gen(g), pred(p) {}
915
920 bool done() {
921 if (!droped) do_drop();
922 return gen.done();
923 }
924
928 auto current() -> decltype(gen.current()) { return gen.current(); }
929
933 void advance() { gen.advance(); }
934 };
935
943 template <class Iter>
944 Views<Iter> views(Iter begin, Iter end) {
945 return Views<Iter>(begin, end);
946 }
947
954 template <class Container>
956 return {std::begin(container), std::end(container)};
957 }
958
965 template <class T>
966 List<T> list(std::initializer_list<T> list) {
967 return List<T>(list);
968 }
969
977 template <class Iterator>
978 List<typename std::decay<typename Iterator::value_type>::type>
979 list(Iterator begin, Iterator end) {
980 return List<
981 typename std::decay<typename Iterator::value_type>::type>(
982 begin, end);
983 }
984
991 template <class Container>
994 std::begin(container), std::end(container));
995 }
996
1005 template <class T>
1006 Range<T> range(T begin, T end, T step = 1) {
1007 return Range<T>(begin, end, step);
1008 }
1009
1016 template <class T>
1018 return Range<T>(end);
1019 }
1020
1028 template <class T>
1029 Repeat<T> repeat(T val, size_t n) {
1030 return Repeat<T>(val, n);
1031 }
1032
1039 template <class T>
1041 return Repeat<T>(val);
1042 }
1043
1050 template <class T>
1051 Cycle<T> cycle(std::initializer_list<T> list) {
1052 return Cycle<T>(list);
1053 }
1054
1062 template <class Iterator>
1063 Cycle<typename std::decay<typename Iterator::value_type>::type>
1064 cycle(Iterator begin, Iterator end) {
1065 return Cycle<
1066 typename std::decay<typename Iterator::value_type>::type>(
1067 begin, end);
1068 }
1069
1076 template <class Container>
1077 Cycle<typename Container::value_type>
1078 cycle(const Container &container) {
1079 return Cycle<
1080 typename std::decay<typename Container::value_type>::type>(
1081 container.begin(), container.end());
1082 }
1083
1092 template <class T>
1093 inline Counter<T>
1094 counter(T start = T{0}, T step = T{1}, size_t times = size_t(-1)) {
1095 return Counter<T>(start, step, times);
1096 }
1097
1102 template <class Func>
1103 class map_t {
1104 Func func;
1105
1106 public:
1107 explicit map_t(Func f) : func(f) {}
1108
1109 template <class Gen>
1110 friend Map<Gen, Func> operator|(Gen g, map_t m) {
1111 return Map<Gen, Func>(g, m.func);
1112 }
1113 };
1114
1121 template <class Func>
1123 return map_t<Func>(f);
1124 }
1125
1130 template <class Pred>
1131 class filter_t {
1132 Pred pred;
1133
1134 public:
1135 explicit filter_t(Pred p) : pred(p) {}
1136
1137 template <class Gen>
1139 return Filter<Gen, Pred>(g, f.pred);
1140 }
1141 };
1142
1149 template <class Pred>
1151 return filter_t<Pred>(pred);
1152 }
1153
1157 class take_t {
1158 size_t count;
1159
1160 public:
1161 explicit take_t(size_t n) : count(n) {}
1162
1163 template <class Gen>
1164 friend Take<Gen> operator|(Gen g, take_t t) {
1165 return Take<Gen>(g, t.count);
1166 }
1167 };
1168
1174 inline take_t take(size_t n) {
1175 return take_t(n);
1176 }
1177
1181 class drop_t {
1182 size_t count;
1183
1184 public:
1185 explicit drop_t(size_t n) : count(n) {}
1186
1187 template <class Gen>
1188 friend Drop<Gen> operator|(Gen g, drop_t s) {
1189 return Drop<Gen>(g, s.count);
1190 }
1191 };
1192
1198 inline drop_t drop(size_t n) {
1199 return drop_t(n);
1200 }
1201
1206 public:
1207 explicit enumerate_t() = default;
1208
1209 template <class Gen>
1211 return Enumerate<Gen>(g);
1212 }
1213
1214 template <class Gen>
1216 return Enumerate<Gen>(g);
1217 }
1218 };
1219
1220 static constexpr enumerate_t enumerate;
1221
1228 template <class Func>
1230 return Generate<Func>(func);
1231 }
1232
1241 template <class Gen1, class Gen2>
1242 Zip<typename std::decay<Gen1>::type, typename std::decay<Gen2>::type>
1243 zip(Gen1 &&g1, Gen2 &&g2) {
1245 typename std::decay<Gen2>::type>(
1246 std::forward<Gen1>(g1), std::forward<Gen2>(g2));
1247 }
1248
1252 template <class Pred>
1254 Pred pred;
1255
1256 public:
1257 explicit take_while_t(Pred p) : pred(p) {}
1258
1259 template <class Gen>
1261 return TakeWhile<Gen, Pred>(g, tw.pred);
1262 }
1263 };
1264
1270 template <class Pred>
1271 inline take_while_t<Pred> take_while(Pred pred) {
1272 return take_while_t<Pred>(pred);
1273 }
1274
1278 template <class Pred>
1280 Pred pred;
1281
1282 public:
1283 explicit drop_while_t(Pred p) : pred(p) {}
1284
1285 template <class Gen>
1287 return DropWhile<Gen, Pred>(g, dw.pred);
1288 }
1289 };
1290
1296 template <class Pred>
1297 inline drop_while_t<Pred> drop_while(Pred pred) {
1298 return drop_while_t<Pred>(pred);
1299 }
1300
1307 template <class Container = void>
1308 class collect {
1309 private:
1317 template <class Range, class C>
1318 static C impl(Range r, std::false_type) {
1319 return C(r.begin(), r.end());
1320 }
1321
1329 template <class Range, class>
1330 static std::vector<
1331 typename std::decay<typename Range::value_type>::type>
1332 impl(Range r, std::true_type) {
1333 return {r.begin(), r.end()};
1334 }
1335
1336 public:
1343 template <class Range>
1346 r, std::is_same<Container, void>{})) {
1348 r, std::is_same<Container, void>{});
1349 }
1350 };
1351
1356 template <class Iterator>
1357 class to_t {
1358 Iterator it;
1359
1360 public:
1361 explicit to_t(Iterator i) : it(i) {}
1362
1363 template <class Range>
1364 friend void operator|(Range r, to_t m) {
1365 std::copy(r.begin(), r.end(), m.it);
1366 }
1367 };
1368
1375 template <class Iterator>
1376 to_t<Iterator> to(Iterator it) {
1377 return to_t<Iterator>(it);
1378 }
1379
1388 template <class Gen1, class Gen2>
1389 auto operator&(Gen1 &&g1, Gen2 &&g2) -> decltype(gen::zip(
1390 std::forward<Gen1>(g1), std::forward<Gen2>(g2))) {
1391 return gen::zip(std::forward<Gen1>(g1), std::forward<Gen2>(g2));
1392 }
1393 }
1394
1395 namespace ops {
1400 template <class T>
1401 struct Add {
1403
1409 template <class U>
1410 auto operator()(U x) const -> decltype(x + value) {
1411 return x + value;
1412 }
1413 };
1414
1419 template <class T>
1420 struct Sub {
1422
1428 template <class U>
1429 auto operator()(U x) const -> decltype(x - value) {
1430 return x - value;
1431 }
1432 };
1433
1438 template <class T>
1439 struct Mul {
1441
1447 template <class U>
1448 auto operator()(U x) const -> decltype(x * value) {
1449 return x * value;
1450 }
1451 };
1452
1457 template <class T>
1458 struct Div {
1460
1466 template <class U>
1467 auto operator()(U x) const -> decltype(x / value) {
1468 return x / value;
1469 }
1470 };
1471
1476 template <class T>
1477 struct Mod {
1479
1485 template <class U>
1486 auto operator()(U x) const -> decltype(x % value) {
1487 return x % value;
1488 }
1489 };
1490
1494 struct inc_t {
1500 template <class T>
1501 auto
1502 operator()(T x) const -> typename std::decay<decltype(++x)>::type {
1503 return ++x;
1504 }
1505 };
1506
1507 static constexpr inc_t inc;
1508
1512 struct dec_t {
1518 template <class T>
1519 auto
1520 operator()(T x) const -> typename std::decay<decltype(--x)>::type {
1521 return --x;
1522 }
1523 };
1524
1525 static constexpr dec_t dec;
1526
1530 struct negate_t {
1536 template <class T>
1537 auto operator()(T x) const -> decltype(-x) {
1538 return -x;
1539 }
1540 };
1541
1542 static constexpr negate_t negate;
1543
1547 struct square_t {
1553 template <class T>
1554 auto operator()(T x) const -> decltype(x * x) {
1555 return x * x;
1556 }
1557 };
1558
1559 static constexpr square_t square;
1560
1564 struct cube_t {
1570 template <class T>
1571 auto operator()(T x) const -> decltype(x * x * x) {
1572 return x * x * x;
1573 }
1574 };
1575
1576 static constexpr cube_t cube;
1577
1581 struct sqrt_t {
1587 template <class T>
1588 auto operator()(T x) const -> decltype(std::sqrt(x)) {
1589 return std::sqrt(x);
1590 }
1591 };
1592
1593 static constexpr sqrt_t sqrt;
1594
1604 template <class T>
1605 auto operator()(T x) const -> decltype(1 / x) {
1606 return 1 / x;
1607 }
1608 };
1609
1610 static constexpr reciprocal_t reciprocal;
1611
1615 struct abs_t {
1621 template <class T>
1622 auto operator()(T x) const -> decltype(std::abs(x)) {
1623 return std::abs(x);
1624 }
1625 };
1626
1627 static constexpr abs_t abs;
1628
1638 template <class T>
1639 std::string operator()(const T &x) const {
1640 return std::to_string(x);
1641 }
1642 };
1643
1644 static constexpr to_string_t to_string;
1645
1650 template <class T>
1651 struct Gt {
1653
1659 template <class U>
1660 bool operator()(const U &x) const {
1661 return x > threshold;
1662 }
1663 };
1664
1669 template <class T>
1670 struct Ge {
1672
1678 template <class U>
1679 bool operator()(const U &x) const {
1680 return x >= threshold;
1681 }
1682 };
1683
1688 template <class T>
1689 struct Lt {
1691
1697 template <class U>
1698 bool operator()(const U &x) const {
1699 return x < threshold;
1700 }
1701 };
1702
1707 template <class T>
1708 struct Le {
1710
1716 template <class U>
1717 bool operator()(const U &x) const {
1718 return x <= threshold;
1719 }
1720 };
1721
1726 template <class T>
1727 struct Eq {
1729
1735 template <class U>
1736 bool operator()(const U &x) const {
1737 return x == value;
1738 }
1739 };
1740
1745 template <class T>
1746 struct Ne {
1748
1754 template <class U>
1755 bool operator()(const U &x) const {
1756 return x != value;
1757 }
1758 };
1759
1763 struct even_t {
1769 template <class T>
1770 bool operator()(T x) const {
1771 return x % 2 == 0;
1772 }
1773 };
1774
1775 static constexpr even_t even;
1776
1780 struct odd_t {
1786 template <class T>
1787 bool operator()(T x) const {
1788 return x % 2 != 0;
1789 }
1790 };
1791
1792 static constexpr odd_t odd;
1793
1797 struct positive_t {
1803 template <class T>
1804 bool operator()(T x) const {
1805 return x > 0;
1806 }
1807 };
1808
1809 static constexpr positive_t positive;
1810
1814 struct negative_t {
1820 template <class T>
1821 bool operator()(T x) const {
1822 return x < 0;
1823 }
1824 };
1825
1826 static constexpr negative_t negative;
1827
1831 struct zero_t {
1837 template <class T>
1838 bool operator()(T x) const {
1839 return x == 0;
1840 }
1841 };
1842
1843 static constexpr zero_t zero;
1844
1848 struct prime_t {
1854 template <class Int>
1855 bool operator()(Int n) const {
1856 if (n <= 1) return false;
1857 for (size_t i = 2; i * i <= n; ++i)
1858 if (n % i == 0) return false;
1859 return true;
1860 }
1861 };
1862
1863 static constexpr prime_t prime;
1864
1870 template <class P, typename Q>
1871 struct And {
1874
1880 template <class T>
1881 bool operator()(const T &x) const {
1882 return p(x) && q(x);
1883 }
1884 };
1885
1891 template <class P, typename Q>
1892 struct Or {
1895
1901 template <class T>
1902 bool operator()(const T &x) const {
1903 return p(x) || q(x);
1904 }
1905 };
1906
1911 template <class P>
1912 struct Not {
1914
1920 template <class T>
1921 bool operator()(const T &x) const {
1922 return !p(x);
1923 }
1924 };
1925
1931 template <class Class, class Mem>
1932 struct Member {
1933 Mem Class::*ptr;
1934
1940 template <class T>
1941 Mem operator()(T &&obj) const {
1942 return obj.*ptr;
1943 }
1944
1950 template <class T>
1951 Mem operator()(T *obj) const {
1952 return obj->*ptr;
1953 }
1954 };
1955
1959 struct first_t {
1965 template <class Pair>
1966 typename Pair::first_type operator()(const Pair &p) const {
1967 return p.first;
1968 }
1969 };
1970
1971 static constexpr first_t first;
1972
1976 struct second_t {
1982 template <class Pair>
1983 typename Pair::second_type operator()(const Pair &p) const {
1984 return p.second;
1985 }
1986 };
1987
1988 static constexpr second_t second;
1989
1994 template <class T>
1995 struct unique {
1996 bool first = true;
1998
2004 bool operator()(const T &x) {
2005 if (first) {
2006 first = false;
2007 last = x;
2008 return true;
2009 }
2010 if (last == x) return false;
2011 last = x;
2012 return true;
2013 }
2014 };
2015
2019 struct identity_t {
2025 template <class T>
2026 T operator()(T x) const {
2027 return x;
2028 }
2029 };
2030
2031 static constexpr identity_t identity;
2032
2037 template <class T>
2038 struct as {
2045 template <class U>
2046 T operator()(U &&x) {
2047 return static_cast<T>(std::forward<U>(x));
2048 }
2049 };
2050
2056 template <class T>
2058 return {v};
2059 }
2060
2065 template <class T>
2067 return {v};
2068 }
2069
2074 template <class T>
2076 return {v};
2077 }
2078
2083 template <class T>
2085 return {v};
2086 }
2087
2092 template <class T>
2094 return {v};
2095 }
2096
2100 template <class T>
2101 Gt<T> gt(T t) {
2102 return {t};
2103 }
2104
2108 template <class T>
2109 Ge<T> ge(T t) {
2110 return {t};
2111 }
2112
2116 template <class T>
2117 Lt<T> lt(T t) {
2118 return {t};
2119 }
2120
2124 template <class T>
2125 Le<T> le(T t) {
2126 return {t};
2127 }
2128
2132 template <class T>
2133 Eq<T> eq(T v) {
2134 return {v};
2135 }
2136
2140 template <class T>
2141 Ne<T> ne(T v) {
2142 return {v};
2143 }
2144
2148 template <class P, typename Q>
2149 And<P, Q> and_(P p, Q q) {
2150 return {p, q};
2151 }
2152
2156 template <class P, typename Q>
2157 Or<P, Q> or_(P p, Q q) {
2158 return {p, q};
2159 }
2160
2164 template <class P>
2166 return {p};
2167 }
2168
2172 template <class Class, typename Mem>
2174 return {p};
2175 }
2176
2181 template <class P, class Q>
2183 return {p, q};
2184 }
2185
2190 template <class P, class Q>
2192 return {p, q};
2193 }
2194
2199 template <class P>
2201 return {p};
2202 }
2203
2209 template <class F, class G>
2210 struct Compose {
2211 F f;
2212 G g;
2213
2220 template <class T>
2221 auto operator()(T x) const -> decltype(g(f(x))) {
2222 return g(f(x));
2223 }
2224 };
2225
2234 template <class F, class G>
2236 return {f, g};
2237 }
2238
2247 template <class F, class... Rest>
2248 auto
2249 compose(F f, Rest... rest) -> Compose<F, decltype(compose(rest...))> {
2250 return {f, compose(rest...)};
2251 }
2252
2261 template <class F, class G>
2263 return {f, g};
2264 }
2265 }
2266}
生成器迭代器类,实现输入迭代器接口。
Definition gen.h:56
std::ptrdiff_t difference_type
Definition gen.h:63
void pointer
Definition gen.h:62
iterator & operator++()
前缀自增操作符,移动到下一个元素。
Definition gen.h:86
bool done()
检查生成器是否已完成。
Definition gen.h:131
std::input_iterator_tag iterator_category
Definition gen.h:64
reference operator*()
解引用操作符,获取当前值。
Definition gen.h:77
Derived d
Definition gen.h:57
bool operator==(const iterator &)
相等比较操作符。
Definition gen.h:107
const iterator operator++(int)
后缀自增操作符,移动到下一个元素。
Definition gen.h:96
T reference
Definition gen.h:61
iterator(const Derived &d)
构造函数,使用派生类引用初始化迭代器。
Definition gen.h:70
bool operator!=(const iterator &)
不等比较操作符。
Definition gen.h:113
T next()
获取当前值并移动到下一个位置。
Definition gen.h:120
T value_type
Definition gen.h:60
生成器模板类,用于创建可迭代的序列生成器。
Definition gen.h:51
iterator begin() const
获取开始迭代器。
Definition gen.h:146
bool done()
检查生成器是否已完成。
Definition gen.h:160
T current()
获取当前值。
Definition gen.h:166
iterator iter() const
获取生成器的迭代器对象。
Definition gen.h:138
T value_type
生成器产生的值类型。
Definition gen.h:154
iterator end() const
获取结束迭代器。
Definition gen.h:152
void advance()
推进生成器到下一个位置。
Definition gen.h:171
StopIteration(const std::string &msg)
构造 StopIteration。
Definition csexc.h:180
size_t max_count
Definition gen.h:482
void advance()
向前移动一步。
Definition gen.h:514
T curr
Definition gen.h:480
Counter(T start=T{0}, T step=T{1}, size_t times=size_t(-1))
构造函数,创建有限计数器。
Definition gen.h:492
T current()
获取当前值。
Definition gen.h:508
T step
Definition gen.h:481
bool done()
检查生成器是否已完成。
Definition gen.h:500
size_t count
Definition gen.h:483
循环生成器,无限循环遍历给定列表。
Definition gen.h:428
bool done()
检查生成器是否已完成。
Definition gen.h:461
T current()
获取当前值。
Definition gen.h:467
Cycle(std::initializer_list< T > list)
构造函数,使用初始化列表。
Definition gen.h:437
Cycle(Iterator begin, Iterator end)
构造函数,使用迭代器范围初始化。
Definition gen.h:446
Cycle(const Container &container)
构造函数,使用容器初始化。
Definition gen.h:454
void advance()
向前移动一步。
Definition gen.h:472
size_t index
Definition gen.h:430
std::vector< T > data
Definition gen.h:429
跳过前n个元素的生成器适配器。
Definition gen.h:677
void do_drop()
执行跳过操作。
Definition gen.h:685
Gen gen
Definition gen.h:678
bool done()
检查生成器是否已完成。
Definition gen.h:702
auto current() -> decltype(gen.current())
获取当前值。
Definition gen.h:711
bool droped
Definition gen.h:680
Drop(Gen g, size_t n)
构造函数。
Definition gen.h:696
size_t count
Definition gen.h:679
void advance()
向前移动一步。
Definition gen.h:719
跳过前若干个元素直到谓词不成立。
Definition gen.h:900
void advance()
向前移动一步。
Definition gen.h:933
void do_drop()
执行跳过操作。
Definition gen.h:908
bool droped
Definition gen.h:903
auto current() -> decltype(gen.current())
获取当前值。
Definition gen.h:928
bool done()
检查生成器是否已完成。
Definition gen.h:920
Gen gen
Definition gen.h:901
Pred pred
Definition gen.h:902
DropWhile(Gen g, Pred p)
Definition gen.h:914
枚举生成器,为每个元素附加索引。
Definition gen.h:732
bool done()
检查生成器是否已完成。
Definition gen.h:747
void advance()
向前移动一步。
Definition gen.h:760
Gen gen
Definition gen.h:733
size_t index
Definition gen.h:734
Enumerate(Gen g)
构造函数。
Definition gen.h:741
auto current() -> decltype(std::make_pair(index, gen.current()))
获取当前值。
Definition gen.h:753
过滤生成器,只保留满足谓词的元素。
Definition gen.h:569
bool done()
检查生成器是否已完成。
Definition gen.h:602
bool valid
Definition gen.h:572
bool initialized
Definition gen.h:573
Filter(Gen g, Pred p)
构造函数。
Definition gen.h:595
Pred pred
Definition gen.h:571
Gen gen
Definition gen.h:570
void advance()
向前移动一步。
Definition gen.h:625
void find_next()
查找下一个满足谓词的元素。
Definition gen.h:578
auto current() -> decltype(gen.current())
获取当前值。
Definition gen.h:614
生成器,通过反复调用函数生成无限序列。
Definition gen.h:772
Generate(Func f)
构造函数。
Definition gen.h:781
decltype(func()) curr
Definition gen.h:774
void advance()
向前移动一步。
Definition gen.h:798
decltype(curr) current()
获取当前值。
Definition gen.h:793
Func func
Definition gen.h:773
bool done()
检查生成器是否已完成。
Definition gen.h:787
用书数据的序列,从初始化列表构造。
Definition gen.h:292
List(Iterator begin, Iterator end)
构造函数,使用迭代器范围初始化。
Definition gen.h:310
std::vector< T > data
Definition gen.h:293
T current()
获取当前值。
Definition gen.h:329
List(const Container &container)
构造函数,使用容器初始化。
Definition gen.h:318
List(std::initializer_list< T > list)
构造函数,使用初始化列表初始化。
Definition gen.h:301
void advance()
向前移动一步。
Definition gen.h:334
bool done()
检查生成器是否已完成。
Definition gen.h:324
size_t idx
Definition gen.h:294
映射生成器,对源生成器的每个元素应用函数。
Definition gen.h:530
bool done()
检查生成器是否已完成。
Definition gen.h:548
ResultType current()
获取当前值。
Definition gen.h:554
void advance()
向前移动一步。
Definition gen.h:559
Map(Gen g, Func f)
构造函数。
Definition gen.h:542
typename std::decay< decltype(func(gen.current()))>::type ResultType
Definition gen.h:533
Func func
Definition gen.h:532
Gen gen
Definition gen.h:531
范围生成器,生成从start到end的等差数列。
Definition gen.h:342
Range(T begin, T end, T step=1)
构造函数。
Definition gen.h:353
T current()
获取当前值。
Definition gen.h:372
T curr
Definition gen.h:343
T end_
Definition gen.h:343
T step
Definition gen.h:344
void advance()
向前移动一步。
Definition gen.h:377
T start
Definition gen.h:343
bool done()
检查生成器是否已完成。
Definition gen.h:366
Range(T end)
构造函数。
Definition gen.h:360
重复生成器,重复生成同一个值指定次数。
Definition gen.h:385
Repeat(T val)
构造函数。
Definition gen.h:403
size_t count
Definition gen.h:387
T value
Definition gen.h:386
Repeat(T val, size_t n)
构造函数。
Definition gen.h:396
size_t index
Definition gen.h:388
T current()
获取当前值。
Definition gen.h:415
void advance()
向前移动一步。
Definition gen.h:420
bool done()
检查生成器是否已完成。
Definition gen.h:409
取前n个元素的生成器适配器。
Definition gen.h:637
size_t taken
Definition gen.h:640
Take(Gen g, size_t n)
构造函数。
Definition gen.h:648
void advance()
向前移动一步。
Definition gen.h:665
Gen gen
Definition gen.h:638
auto current() -> decltype(gen.current())
获取当前值。
Definition gen.h:660
size_t count
Definition gen.h:639
bool done()
检查生成器是否已完成。
Definition gen.h:654
取得前若干个元素直到谓词不成立。
Definition gen.h:852
TakeWhile(Gen g, Pred p)
构造函数。
Definition gen.h:870
bool done()
检查生成器是否已完成。
Definition gen.h:876
void try_advance()
Definition gen.h:857
auto current() -> decltype(gen.current())
获取当前值。
Definition gen.h:882
void advance()
向前移动一步。
Definition gen.h:887
Pred pred
Definition gen.h:854
Gen gen
Definition gen.h:853
bool stopped
Definition gen.h:855
迭代器范围生成器,生成从begin到end的值。
Definition gen.h:244
bool done()
检查生成器是否已完成。
Definition gen.h:271
void advance()
向前移动一步。
Definition gen.h:282
Views(Iter begin, Iter end)
构造函数,使用迭代器范围初始化。
Definition gen.h:256
Iter end_
Definition gen.h:246
Iter curr
Definition gen.h:245
typename std::iterator_traits< Iter >::value_type value_type
Definition gen.h:249
value_type current()
获取当前值。
Definition gen.h:277
Views(const Container &container)
构造函数,使用容器引用初始化。
Definition gen.h:264
压缩生成器,将两个生成器的元素配对输出。
Definition gen.h:809
Gen2 gen2
Definition gen.h:811
Zip(Gen1 g1, Gen2 g2)
构造函数。
Definition gen.h:819
void advance()
向前移动一步。
Definition gen.h:839
std::pair< typename Gen1::value_type, typename Gen2::value_type > current()
获取当前值。
Definition gen.h:832
bool done()
检查生成器是否已完成。
Definition gen.h:825
Gen1 gen1
Definition gen.h:810
容器收集适配器。
Definition gen.h:1308
friend auto operator|(Range r, collect< Container >) -> decltype(collect< Container >::template impl< Range, Container >(r, std::is_same< Container, void >{}))
管道操作符,将范围元素收集到容器中。
Definition gen.h:1344
static std::vector< typename std::decay< typename Range::value_type >::type > impl(Range r, std::true_type)
void版本的实现,将范围元素拷贝到std::vector。
Definition gen.h:1332
static C impl(Range r, std::false_type)
非void版本的实现,将范围元素拷贝到指定容器。
Definition gen.h:1318
跳过前n个元素适配器(用于管道操作符)。
Definition gen.h:1181
size_t count
Definition gen.h:1182
drop_t(size_t n)
Definition gen.h:1185
friend Drop< Gen > operator|(Gen g, drop_t s)
Definition gen.h:1188
跳过前若干个元素适配器(用于管道操作符)。
Definition gen.h:1279
drop_while_t(Pred p)
Definition gen.h:1283
Pred pred
Definition gen.h:1280
friend DropWhile< Gen, Pred > operator|(Gen g, drop_while_t dw)
Definition gen.h:1286
枚举生成器,为每个元素附加索引。
Definition gen.h:1205
friend Enumerate< Gen > operator|(Gen g, enumerate_t)
Definition gen.h:1210
Enumerate< Gen > operator()(Gen g)
Definition gen.h:1215
过滤适配器(用于管道操作符)。
Definition gen.h:1131
filter_t(Pred p)
Definition gen.h:1135
Pred pred
Definition gen.h:1132
friend Filter< Gen, Pred > operator|(Gen g, filter_t f)
Definition gen.h:1138
映射适配器(用于管道操作符)。
Definition gen.h:1103
map_t(Func f)
Definition gen.h:1107
friend Map< Gen, Func > operator|(Gen g, map_t m)
Definition gen.h:1110
Func func
Definition gen.h:1104
取前n个元素适配器(用于管道操作符)。
Definition gen.h:1157
friend Take< Gen > operator|(Gen g, take_t t)
Definition gen.h:1164
size_t count
Definition gen.h:1158
take_t(size_t n)
Definition gen.h:1161
取前若干个元素适配器(用于管道操作符)。
Definition gen.h:1253
Pred pred
Definition gen.h:1254
take_while_t(Pred p)
Definition gen.h:1257
friend TakeWhile< Gen, Pred > operator|(Gen g, take_while_t tw)
Definition gen.h:1260
创建目标迭代器适配器。
Definition gen.h:1357
friend void operator|(Range r, to_t m)
Definition gen.h:1364
to_t(Iterator i)
Definition gen.h:1361
Iterator it
Definition gen.h:1358
定义 console 库使用的自定义异常类层次结构。
std::enable_if< is_string< typenamestd::decay< T >::type >::value >::type repr(T &&value, std::basic_ostream< CharT, Traits > &os=std::cout)
输出字符串类型(std::string, const char* 等)的表示,带双引号。
Definition repr.h:97
提供些许关于迭代器的拓展功能。
Definition gen.h:237
Range< T > range(T begin, T end, T step=1)
创建范围生成器。
Definition gen.h:1006
auto operator&(Gen1 &&g1, Gen2 &&g2) -> decltype(gen::zip(std::forward< Gen1 >(g1), std::forward< Gen2 >(g2)))
按位与操作符重载,用于压缩两个生成器。
Definition gen.h:1389
map_t< Func > map(Func f)
创建映射适配器。
Definition gen.h:1122
drop_while_t< Pred > drop_while(Pred pred)
创建跳过前若干个元素适配器。
Definition gen.h:1297
Zip< typename std::decay< Gen1 >::type, typename std::decay< Gen2 >::type > zip(Gen1 &&g1, Gen2 &&g2)
压缩两个生成器。
Definition gen.h:1243
drop_t drop(size_t n)
创建跳过前n个元素适配器。
Definition gen.h:1198
take_while_t< Pred > take_while(Pred pred)
创建取前若干个元素适配器。
Definition gen.h:1271
Views< Iter > views(Iter begin, Iter end)
从迭代器范围创建视图生成器。
Definition gen.h:944
to_t< Iterator > to(Iterator it)
创建目标迭代器适配器。
Definition gen.h:1376
take_t take(size_t n)
创建取前n个元素适配器。
Definition gen.h:1174
List< T > list(std::initializer_list< T > list)
从初始化列表创建列表生成器。
Definition gen.h:966
Generate< Func > generate(Func func)
创建生成器适配器。
Definition gen.h:1229
Counter< T > counter(T start=T{0}, T step=T{1}, size_t times=size_t(-1))
创建计数器生成器。
Definition gen.h:1094
Cycle< T > cycle(std::initializer_list< T > list)
创建循环生成器。
Definition gen.h:1051
filter_t< Pred > filter(Pred pred)
创建过滤适配器。
Definition gen.h:1150
static constexpr enumerate_t enumerate
Definition gen.h:1220
Repeat< T > repeat(T val, size_t n)
创建重复生成器。
Definition gen.h:1029
Definition gen.h:1395
Compose< F, G > compose(F f, G g)
将两个函数组合为一个函数。
Definition gen.h:2235
static constexpr sqrt_t sqrt
Definition gen.h:1593
static constexpr odd_t odd
Definition gen.h:1792
Not< P > not_(P p)
创建逻辑非组合谓词。
Definition gen.h:2165
static constexpr square_t square
Definition gen.h:1559
static constexpr reciprocal_t reciprocal
Definition gen.h:1610
Or< P, Q > operator||(P p, Q q)
逻辑或运算符,等价于 or_(p, q)。
Definition gen.h:2191
Compose< F, G > operator>>(F f, G g)
函数组合运算符,将两个函数组合为一个函数。
Definition gen.h:2262
Not< P > operator!(P p)
逻辑非运算符,等价于 not_(p)。
Definition gen.h:2200
static constexpr second_t second
Definition gen.h:1988
Mod< T > mod(T v)
创建取模固定值变换器。
Definition gen.h:2093
And< P, Q > and_(P p, Q q)
创建逻辑与组合谓词。
Definition gen.h:2149
static constexpr negate_t negate
Definition gen.h:1542
static constexpr prime_t prime
Definition gen.h:1863
static constexpr negative_t negative
Definition gen.h:1826
Gt< T > gt(T t)
创建大于谓词。
Definition gen.h:2101
static constexpr inc_t inc
Definition gen.h:1507
Mul< T > mul(T v)
创建乘固定值变换器。
Definition gen.h:2075
Le< T > le(T t)
创建小于等于谓词。
Definition gen.h:2125
static constexpr cube_t cube
Definition gen.h:1576
Member< Class, Mem > member(Mem Class::*p)
创建成员变量访问器。
Definition gen.h:2173
Ne< T > ne(T v)
创建不等于谓词。
Definition gen.h:2141
static constexpr first_t first
Definition gen.h:1971
Add< T > add(T v)
创建加固定值变换器。
Definition gen.h:2057
static constexpr abs_t abs
Definition gen.h:1627
Lt< T > lt(T t)
创建小于谓词。
Definition gen.h:2117
static constexpr identity_t identity
Definition gen.h:2031
static constexpr dec_t dec
Definition gen.h:1525
Div< T > div(T v)
创建除固定值变换器。
Definition gen.h:2084
static constexpr positive_t positive
Definition gen.h:1809
static constexpr to_string_t to_string
Definition gen.h:1644
static constexpr even_t even
Definition gen.h:1775
static constexpr zero_t zero
Definition gen.h:1843
Eq< T > eq(T v)
创建等于谓词。
Definition gen.h:2133
And< P, Q > operator&&(P p, Q q)
逻辑与运算符,等价于 and_(p, q)。
Definition gen.h:2182
Sub< T > sub(T v)
创建减固定值变换器。
Definition gen.h:2066
Ge< T > ge(T t)
创建大于等于谓词。
Definition gen.h:2109
Or< P, Q > or_(P p, Q q)
创建逻辑或组合谓词。
Definition gen.h:2157
本库所有组件所在的顶层命名空间。
Generator< Derived, T >::iterator iter(Generator< Derived, T > &g)
获取生成器迭代器的辅助函数。
Definition gen.h:180
@ C
Definition kb.h:82
@ P
Definition kb.h:95
@ T
Definition kb.h:99
@ Q
Definition kb.h:96
std::basic_ostream< CharT, Traits > & print_generator(std::basic_ostream< CharT, Traits > &os, const Generator< Derived, T > &gen)
将 Generator 的内容输出到流,格式为 [elem1, elem2, ...]。
Definition gen.h:209
MultiArray< decltype(std::declval< T >()<< std::declval< U >()), Dims... > operator<<(const MultiArray< T, Dims... > &a, const MultiArray< U, Dims... > &b)
Definition multiarray.h:1607
T next(typename Generator< Derived, T >::iterator &it)
从迭代器获取下一个值的辅助函数。
Definition gen.h:190
提供类似 Python 的 repr() 函数,用于生成对象的可读字符串表示。
加固定值变换器。
Definition gen.h:1401
auto operator()(U x) const -> decltype(x+value)
对输入值加上固定值。
Definition gen.h:1410
T value
Definition gen.h:1402
逻辑与组合器。
Definition gen.h:1871
bool operator()(const T &x) const
对输入值同时应用两个谓词并返回逻辑与结果。
Definition gen.h:1881
P p
Definition gen.h:1872
Q q
Definition gen.h:1873
函数组合器,将两个函数组合为一个函数。
Definition gen.h:2210
auto operator()(T x) const -> decltype(g(f(x)))
对输入值应用两个函数的组合。
Definition gen.h:2221
F f
Definition gen.h:2211
G g
Definition gen.h:2212
除固定值变换器。
Definition gen.h:1458
auto operator()(U x) const -> decltype(x/value)
对输入值除以固定值。
Definition gen.h:1467
T value
Definition gen.h:1459
等于谓词。
Definition gen.h:1727
T value
Definition gen.h:1728
bool operator()(const U &x) const
判断输入值是否等于指定值。
Definition gen.h:1736
大于等于谓词。
Definition gen.h:1670
bool operator()(const U &x) const
判断输入值是否大于等于阈值。
Definition gen.h:1679
T threshold
Definition gen.h:1671
大于谓词。
Definition gen.h:1651
bool operator()(const U &x) const
判断输入值是否大于阈值。
Definition gen.h:1660
T threshold
Definition gen.h:1652
小于等于谓词。
Definition gen.h:1708
T threshold
Definition gen.h:1709
bool operator()(const U &x) const
判断输入值是否小于等于阈值。
Definition gen.h:1717
小于谓词。
Definition gen.h:1689
bool operator()(const U &x) const
判断输入值是否小于阈值。
Definition gen.h:1698
T threshold
Definition gen.h:1690
取成员变量变换器。
Definition gen.h:1932
Mem Class::* ptr
成员指针
Definition gen.h:1933
Mem operator()(T *obj) const
获取对象的成员变量。
Definition gen.h:1951
Mem operator()(T &&obj) const
获取对象的成员变量。
Definition gen.h:1941
取模固定值变换器。
Definition gen.h:1477
T value
Definition gen.h:1478
auto operator()(U x) const -> decltype(x % value)
对输入值取模固定值。
Definition gen.h:1486
乘固定值变换器。
Definition gen.h:1439
auto operator()(U x) const -> decltype(x *value)
对输入值乘以固定值。
Definition gen.h:1448
T value
Definition gen.h:1440
不等于谓词。
Definition gen.h:1746
bool operator()(const U &x) const
判断输入值是否不等于指定值。
Definition gen.h:1755
T value
Definition gen.h:1747
逻辑非组合器。
Definition gen.h:1912
P p
Definition gen.h:1913
bool operator()(const T &x) const
对输入值应用谓词并返回逻辑非结果。
Definition gen.h:1921
逻辑或组合器。
Definition gen.h:1892
P p
Definition gen.h:1893
Q q
Definition gen.h:1894
bool operator()(const T &x) const
对输入值同时应用两个谓词并返回逻辑或结果。
Definition gen.h:1902
减固定值变换器。
Definition gen.h:1420
auto operator()(U x) const -> decltype(x - value)
对输入值减去固定值。
Definition gen.h:1429
T value
Definition gen.h:1421
绝对值变换器。
Definition gen.h:1615
auto operator()(T x) const -> decltype(std::abs(x))
计算输入值的绝对值。
Definition gen.h:1622
转型变化器。
Definition gen.h:2038
T operator()(U &&x)
返回转型后的值。
Definition gen.h:2046
立方变换器。
Definition gen.h:1564
auto operator()(T x) const -> decltype(x *x *x)
计算输入值的立方。
Definition gen.h:1571
自减变换器。
Definition gen.h:1512
auto operator()(T x) const -> typename std::decay< decltype(--x)>::type
对输入值自减1。
Definition gen.h:1520
偶数谓词。
Definition gen.h:1763
bool operator()(T x) const
判断输入值是否为偶数。
Definition gen.h:1770
取 pair 的 first 变换器。
Definition gen.h:1959
Pair::first_type operator()(const Pair &p) const
获取 pair 的第一个元素。
Definition gen.h:1966
恒等变换器。
Definition gen.h:2019
T operator()(T x) const
返回输入值本身。
Definition gen.h:2026
自增变换器。
Definition gen.h:1494
auto operator()(T x) const -> typename std::decay< decltype(++x)>::type
对输入值自增1。
Definition gen.h:1502
取负变换器。
Definition gen.h:1530
auto operator()(T x) const -> decltype(-x)
对输入值取负。
Definition gen.h:1537
负数谓词。
Definition gen.h:1814
bool operator()(T x) const
判断输入值是否为负数。
Definition gen.h:1821
奇数谓词。
Definition gen.h:1780
bool operator()(T x) const
判断输入值是否为奇数。
Definition gen.h:1787
正数谓词。
Definition gen.h:1797
bool operator()(T x) const
判断输入值是否为正数。
Definition gen.h:1804
素数谓词。
Definition gen.h:1848
bool operator()(Int n) const
判断输入值是否为素数。
Definition gen.h:1855
倒数变换器。
Definition gen.h:1598
auto operator()(T x) const -> decltype(1/x)
计算输入值的倒数。
Definition gen.h:1605
取 pair 的 second 变换器。
Definition gen.h:1976
Pair::second_type operator()(const Pair &p) const
获取 pair 的第二个元素。
Definition gen.h:1983
平方根变换器。
Definition gen.h:1581
auto operator()(T x) const -> decltype(std::sqrt(x))
计算输入值的平方根。
Definition gen.h:1588
平方变换器。
Definition gen.h:1547
auto operator()(T x) const -> decltype(x *x)
计算输入值的平方。
Definition gen.h:1554
转为字符串变换器。
Definition gen.h:1632
std::string operator()(const T &x) const
将输入值转换为字符串。
Definition gen.h:1639
相邻去重过滤器。
Definition gen.h:1995
bool first
Definition gen.h:1996
T last
Definition gen.h:1997
bool operator()(const T &x)
判断当前元素是否与前一个元素不同。
Definition gen.h:2004
零谓词。
Definition gen.h:1831
bool operator()(T x) const
判断输入值是否为零。
Definition gen.h:1838