Console Library 8.0.0
A header-only library that makes C++ simple
Loading...
Searching...
No Matches
gextra.h
Go to the documentation of this file.
1
8
9/*
10Copyright (c) 2026 MrXie1109
11
12Permission is hereby granted, free of charge, to any person obtaining a copy
13of this software and associated documentation files (the "Software"), to deal
14in the Software without restriction, including without limitation the rights
15to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16copies of the Software, and to permit persons to whom the Software is
17furnished to do so, subject to the following conditions:
18
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28SOFTWARE.
29*/
30
31#pragma once
32#include <chrono>
33#include <cmath>
34#include <cstdint>
35#include <fstream>
36#include <iostream>
37#include <memory>
38#include <string>
39#include <tuple>
40
41#include "../core/sfinae.h"
42#include "../util/params.h"
43#include "./gen.h"
44
45namespace console {
46 namespace gen {
51 template <class T>
52 class Random : public Generator<Random<T>, T> {
53 std::mt19937 gen_;
56
57 public:
65 T max,
66 std::mt19937::result_type seed = std::random_device{}()) :
68
73 bool done() { return false; }
74
79 T current() { return curr_; }
80
84 void advance() { curr_ = dist_(gen_); }
85 };
86
90 class FileLines : public Generator<FileLines, std::string> {
91 std::shared_ptr<std::ifstream> file_;
92 std::string current_line_;
93
94 public:
100 explicit FileLines(const std::string &filename) :
101 file_(std::make_shared<std::ifstream>(filename)) {
102 if (!file_->is_open())
103 throw FileError("Cannot Open File \"" + filename + '"');
104 advance();
105 }
106
111 bool done() { return current_line_.empty() && file_->eof(); }
112
117 std::string current() { return current_line_; }
118
122 void advance() {
123 if (!std::getline(*file_, current_line_)) current_line_.clear();
124 }
125 };
126
130 class FileChunks : public Generator<FileChunks, std::string> {
131 std::shared_ptr<std::ifstream> file_;
132 std::string current_chunk_;
134
135 public:
143 explicit FileChunks(const std::string &filename,
144 size_t chunk_size = 1024,
145 std::ios_base::openmode mode = std::ios::in) :
146 file_(std::make_shared<std::ifstream>(filename, mode)),
147 chunk_size_(chunk_size) {
148 if (!file_->is_open())
149 throw FileError("Cannot Open File \"" + filename + '"');
150 advance();
151 }
152
157 bool done() { return file_->eof() && current_chunk_.empty(); }
158
163 std::string current() { return current_chunk_; }
164
168 void advance() {
170 file_->read(&current_chunk_[0], chunk_size_);
171 current_chunk_.resize(file_->gcount());
172 }
173 };
174
179 template <class Gen>
180 class Window : public Generator<Window<Gen>,
181 std::vector<typename Gen::value_type>> {
182 Gen gen_;
184 std::vector<typename Gen::value_type> window_;
185 bool started = false;
186
187 void init() {
188 if (!started) {
189 for (size_t i = 0; i < window_size_ && !gen_.done(); ++i) {
190 window_.push_back(gen_.current());
191 gen_.advance();
192 }
193 started = true;
194 }
195 }
196
197 public:
204 explicit Window(Gen gen, size_t window_size = 16) :
205 gen_(gen), window_size_(window_size) {
206 if (window_size_ == 0)
207 throw ValueError("Window size must be greater than 0");
208 }
209
214 bool done() {
215 init();
216 return window_.size() < window_size_;
217 }
218
223 std::vector<typename Gen::value_type> current() {
224 init();
225 return window_;
226 }
227
231 void advance() {
232 init();
233 if (!gen_.done()) {
234 window_.erase(window_.begin());
235 window_.push_back(gen_.current());
236 gen_.advance();
237 } else
238 window_.erase(window_.begin());
239 }
240 };
241
246 template <class Gen>
247 class Chunk : public Generator<Chunk<Gen>,
248 std::vector<typename Gen::value_type>> {
249 Gen gen_;
251 std::vector<typename Gen::value_type> chunk_;
252 bool started = false;
253
254 void init() {
255 if (!started) {
256 for (size_t i = 0; i < chunk_size_ && !gen_.done(); ++i) {
257 chunk_.push_back(gen_.current());
258 gen_.advance();
259 }
260 started = true;
261 }
262 }
263
264 public:
271 explicit Chunk(Gen gen, size_t chunk_size = 16) :
272 gen_(gen), chunk_size_(chunk_size) {
273 if (chunk_size_ == 0)
274 throw ValueError("Chunk size must be greater than 0");
275 }
276
281 bool done() {
282 init();
283 return chunk_.empty();
284 }
285
290 std::vector<typename Gen::value_type> current() {
291 init();
292 return chunk_;
293 }
294
298 void advance() {
299 init();
300 if (!gen_.done()) {
301 chunk_.clear();
302 for (size_t i = 0; i < chunk_size_ && !gen_.done(); ++i) {
303 chunk_.push_back(gen_.current());
304 gen_.advance();
305 }
306 } else
307 chunk_.clear();
308 }
309 };
310
316 template <class Gen1, class Gen2>
317 class Chain
318 : public Generator<Chain<Gen1, Gen2>,
319 typename std::decay<
320 decltype(true ? std::declval<typename Gen1::value_type>()
321 : std::declval<typename Gen2::
322 value_type>())>::type> {
323 using T = typename std::decay<
324 decltype(true ? std::declval<typename Gen1::value_type>()
325 : std::declval<typename Gen2::value_type>())>::
326 type;
327
328 Gen1 gen1;
329 Gen2 gen2;
330
331 public:
337 Chain(Gen1 g1, Gen2 g2) : gen1(g1), gen2(g2) {}
338
343 bool done() { return gen1.done() && gen2.done(); }
344
350 if (!gen1.done())
351 return gen1.current();
352 else
353 return gen2.current();
354 }
355
359 void advance() {
360 if (!gen1.done())
361 gen1.advance();
362 else
363 gen2.advance();
364 }
365 };
366
371 template <class Gen>
372 class StepBy : public Generator<StepBy<Gen>, typename Gen::value_type> {
373 Gen gen;
374 size_t step;
375
376 public:
383 explicit StepBy(Gen g, size_t s = 1) : gen(g), step(s) {
384 if (step == 0)
385 throw ValueError("Step size must be greater than 0");
386 }
387
392 bool done() { return gen.done(); }
393
398 typename Gen::value_type current() { return gen.current(); }
399
403 void advance() {
404 for (size_t i = 0; i < step && !gen.done(); ++i) gen.advance();
405 }
406 };
407
412 template <class Gen>
413 class Debug : public Generator<Debug<Gen>, typename Gen::value_type> {
414 Gen gen;
415 std::string message;
416 std::ostream &out;
417
418 public:
425 explicit Debug(Gen g,
426 std::string msg = "Current Value: ",
427 std::ostream &os = std::cout) : gen(g), message(msg), out(os) {}
428
433 bool done() { return gen.done(); }
434
439 typename Gen::value_type current() {
440#ifndef NDEBUG
441 out << message << gen.current() << std::endl;
442#endif
443 return gen.current();
444 }
445
449 void advance() { gen.advance(); }
450 };
451
457 template <class Gen, class Pred>
459 : public Generator<TakeUntil<Gen, Pred>, typename Gen::value_type> {
460 Gen gen;
461 Pred pred;
462 bool stopped = false;
463
464 void try_advance() {
465 if (stopped || gen.done()) return;
466 if (pred(gen.current())) {
467 stopped = true;
468 gen.advance();
469 }
470 }
471
472 public:
478 TakeUntil(Gen g, Pred p) : gen(g), pred(p) {}
479
484 bool done() {
485 if (gen.done() || stopped) return true;
486 return false;
487 }
488
493 auto current() -> decltype(gen.current()) { return gen.current(); }
494
498 void advance() {
499 gen.advance();
500 try_advance();
501 }
502 };
503
509 template <class Gen, class Pred>
511 : public Generator<DropUntil<Gen, Pred>, typename Gen::value_type> {
512 Gen gen;
513 Pred pred;
514 bool dropped = false;
515
516 void do_drop() {
517 while (!gen.done() && !pred(gen.current())) gen.advance();
518 dropped = true;
519 }
520
521 public:
527 DropUntil(Gen g, Pred p) : gen(g), pred(p) {}
528
533 bool done() {
534 if (!dropped) do_drop();
535 return gen.done();
536 }
537
542 auto current() -> decltype(gen.current()) { return gen.current(); }
543
547 void advance() { gen.advance(); }
548 };
549
556 template <class... Ops>
557 class Pipeline;
558
563 template <class Op>
564 class Pipeline<Op> {
565 Op op;
566
567 public:
572 Pipeline(Op o) : op(o) {}
573
580 template <class Gen>
581 auto operator()(Gen gen) const -> decltype(gen | op) {
582 return gen | op;
583 }
584 };
585
591 template <class Op, class... Rest>
592 class Pipeline<Op, Rest...> {
593 Op op;
594 Pipeline<Rest...> rest;
595
596 public:
602 Pipeline(Op o, Rest... r) : op(o), rest(r...) {}
603
610 template <class Gen>
611 auto operator()(Gen gen) const -> decltype(rest(gen | op)) {
612 return rest(gen | op);
613 }
614 };
615
621 template <class... Ops>
622 struct pipeline_t {
624
629 pipeline_t(Ops... ops) : pipeline(ops...) {}
630 };
631
639 template <class Gen, class... Ops>
641 -> decltype(pl.pipeline(gen)) {
642 return pl.pipeline(gen);
643 }
644
652 template <class... Ops>
653 pipeline_t<Ops...> pipeline(Ops... ops) {
654 return pipeline_t<Ops...>(ops...);
655 }
656
666 template <class Op1, class Op2>
667 pipeline_t<Op1, Op2> operator%(Op1 op1, Op2 op2) {
668 return pipeline(op1, op2);
669 }
670
671 template <class Gen, class T, class BinaryOp>
672 class Scan : public Generator<Scan<Gen, T, BinaryOp>, T> {
673 Gen gen;
675 BinaryOp op;
676 bool started = false;
677
678 void lazy_init() {
679 if (!started) {
680 state = op(state, gen.current());
681 started = true;
682 }
683 }
684
685 public:
686 Scan(Gen g, T init, BinaryOp o) : gen(g), state(init), op(o) {}
687
688 bool done() {
689 lazy_init();
690 return gen.done();
691 }
692
694 lazy_init();
695 return state;
696 }
697
698 void advance() {
699 lazy_init();
700 gen.advance();
701 if (!gen.done()) state = op(state, gen.current());
702 }
703 };
704
705 // =====================================================================
706
715 template <class T>
717 T max,
718 std::mt19937::result_type seed = std::random_device{}()) {
719 return Random<T>(min, max, seed);
720 }
721
727 inline FileLines file_lines(const std::string &filename) {
728 return FileLines(filename);
729 }
730
738 inline FileChunks file_chunks(const std::string &filename,
739 size_t chunk_size = 1024,
740 std::ios_base::openmode mode = std::ios::in) {
741 return FileChunks(filename, chunk_size, mode);
742 }
743
747 class window_t {
748 size_t s;
749
750 public:
755 explicit window_t(size_t size = 16) : s(size) {}
756
764 template <class Gen>
765 friend Window<Gen> operator|(Gen g, window_t w) {
766 return Window<Gen>(g, w.s);
767 }
768 };
769
775 inline window_t window(size_t size = 16) {
776 return window_t(size);
777 }
778
782 class chunk_t {
783 size_t s;
784
785 public:
790 explicit chunk_t(size_t size = 16) : s(size) {}
791
799 template <class Gen>
800 friend Chunk<Gen> operator|(Gen g, chunk_t t) {
801 return Chunk<Gen>(g, t.s);
802 }
803 };
804
810 inline chunk_t chunk(size_t size = 16) {
811 return chunk_t(size);
812 }
813
822 template <class Gen1, class Gen2>
823 Chain<Gen1, Gen2> chain(Gen1 g1, Gen2 g2) {
824 return Chain<Gen1, Gen2>(g1, g2);
825 }
826
835 template <class Gen, class... Rest>
836 auto
837 chain(Gen g, Rest... rest) -> Chain<Gen, decltype(chain(rest...))> {
838 return {g, chain(rest...)};
839 }
840
849 template <class Gen1, class Gen2>
850 Chain<Gen1, Gen2> operator+(Gen1 g1, Gen2 g2) {
851 return Chain<Gen1, Gen2>(g1, g2);
852 }
853
857 class step_by_t {
858 size_t s;
859
860 public:
865 explicit step_by_t(size_t size = 1) : s(size) {}
866
874 template <class Gen>
876 return StepBy<Gen>(g, s.s);
877 }
878 };
879
885 inline step_by_t step_by(size_t size = 1) {
886 return step_by_t(size);
887 }
888
892 class debug_t {
893 std::string message;
894 std::ostream &out;
895
896 public:
902 explicit debug_t(std::string msg = "DEBUG: ",
903 std::ostream &os = std::cout) : message(msg), out(os) {}
904
912 template <class Gen>
913 friend Debug<Gen> operator|(Gen g, debug_t d) {
914 return Debug<Gen>(g, d.message, d.out);
915 }
916 };
917
924 inline debug_t
925 debug(std::string msg = "DEBUG: ", std::ostream &os = std::cout) {
926 return debug_t{msg, os};
927 }
928
933 template <class Pred>
935 Pred pred;
936
937 public:
942 explicit take_until_t(Pred p) : pred(p) {}
943
951 template <class Gen>
953 return TakeUntil<Gen, Pred>(g, tu.pred);
954 }
955 };
956
963 template <class Pred>
965 return take_until_t<Pred>(p);
966 }
967
972 template <class Pred>
974 Pred pred;
975
976 public:
981 explicit drop_until_t(Pred p) : pred(p) {}
982
990 template <class Gen>
992 return DropUntil<Gen, Pred>(g, du.pred);
993 }
994 };
995
1002 template <class Pred>
1004 return drop_until_t<Pred>(p);
1005 }
1006
1012 template <class T, class BinaryOp>
1013 class reduce_t {
1015 BinaryOp op_;
1016
1017 public:
1023 reduce_t(T init, BinaryOp op) : init_(init), op_(op) {}
1024
1031 template <class Gen>
1032 friend T operator|(Gen gen, reduce_t r) {
1033 T result = r.init_;
1034 for (auto &&item : gen) result = r.op_(result, item);
1035 return result;
1036 }
1037 };
1038
1044 template <class T, class BinaryOp>
1045 reduce_t<T, BinaryOp> reduce(const T &init, BinaryOp bo) {
1046 return reduce_t<T, BinaryOp>(init, bo);
1047 }
1048
1049 template <class T, class BinaryOp>
1050 class scan_t {
1052 BinaryOp op;
1053
1054 public:
1060 scan_t(const T &init, BinaryOp op) : state(init), op(op) {}
1061
1068 template <class Gen>
1071 return Scan<Gen, T, BinaryOp>(gen, scan.state, scan.op);
1072 }
1073 };
1074
1083 template <class T, class BinaryOp>
1084 scan_t<T, BinaryOp> scan(T init, BinaryOp op) {
1085 return scan_t<T, BinaryOp>(init, op);
1086 }
1087
1093 template <class F, class... Args>
1096 Params<Args...> params;
1097
1098 public:
1104 algorithm_t(F func, const Args &...args) :
1105 func(func), params(args...) {}
1106
1113 template <class Gen>
1114 friend auto
1115 operator|(Gen gen, algorithm_t alg) -> decltype(std::declval<F>()(
1116 gen.begin(), gen.end(), std::declval<Args>()...)) {
1117 return alg.params.apply([&](const Args &...args) {
1118 return alg.func(gen.begin(), gen.end(), args...);
1119 });
1120 }
1121 };
1122
1135 template <class T, class... Args>
1136 algorithm_t<T, Args...> algorithm(T func, const Args &...args) {
1137 return algorithm_t<T, Args...>(func, args...);
1138 }
1139 }
1140
1141 namespace ops {
1146 template <class T>
1147 struct Pow {
1149
1155 template <class U>
1156 auto operator()(U x) const -> decltype(std::pow(x, exponent)) {
1157 return std::pow(x, exponent);
1158 }
1159 };
1160
1167 template <class T>
1169 return {exp};
1170 }
1171
1175 struct exp_t {
1181 template <class T>
1182 auto operator()(T x) const -> decltype(std::exp(x)) {
1183 return std::exp(x);
1184 }
1185 };
1186
1187 static constexpr exp_t exp;
1188
1192 struct log10_t {
1198 template <class T>
1199 auto operator()(T x) const -> decltype(std::log10(x)) {
1200 return std::log10(x);
1201 }
1202 };
1203
1204 static constexpr log10_t log10;
1205
1209 struct sin_t {
1215 template <class T>
1216 auto operator()(T x) const -> decltype(std::sin(x)) {
1217 return std::sin(x);
1218 }
1219 };
1220
1221 static constexpr sin_t sin;
1222
1226 struct cos_t {
1232 template <class T>
1233 auto operator()(T x) const -> decltype(std::cos(x)) {
1234 return std::cos(x);
1235 }
1236 };
1237
1238 static constexpr cos_t cos;
1239
1243 struct tan_t {
1249 template <class T>
1250 auto operator()(T x) const -> decltype(std::tan(x)) {
1251 return std::tan(x);
1252 }
1253 };
1254
1255 static constexpr tan_t tan;
1256
1260 struct asin_t {
1266 template <class T>
1267 auto operator()(T x) const -> decltype(std::asin(x)) {
1268 return std::asin(x);
1269 }
1270 };
1271
1272 static constexpr asin_t asin;
1273
1277 struct acos_t {
1283 template <class T>
1284 auto operator()(T x) const -> decltype(std::acos(x)) {
1285 return std::acos(x);
1286 }
1287 };
1288
1289 static constexpr acos_t acos;
1290
1294 struct atan_t {
1300 template <class T>
1301 auto operator()(T x) const -> decltype(std::atan(x)) {
1302 return std::atan(x);
1303 }
1304 };
1305
1306 static constexpr atan_t atan;
1307
1312 struct sign_t {
1318 template <class T>
1319 int operator()(T x) const {
1320 return (x > 0) - (x < 0);
1321 }
1322 };
1323
1324 static constexpr sign_t sign;
1325
1329 struct round_t {
1335 template <class T>
1336 auto operator()(T x) const -> decltype(std::round(x)) {
1337 return std::round(x);
1338 }
1339 };
1340
1341 static constexpr round_t round;
1342
1346 struct ceil_t {
1352 template <class T>
1353 auto operator()(T x) const -> decltype(std::ceil(x)) {
1354 return std::ceil(x);
1355 }
1356 };
1357
1358 static constexpr ceil_t ceil;
1359
1363 struct floor_t {
1369 template <class T>
1370 auto operator()(T x) const -> decltype(std::floor(x)) {
1371 return std::floor(x);
1372 }
1373 };
1374
1375 static constexpr floor_t floor;
1376
1380 struct strlen_t {
1386 size_t operator()(const std::string &s) const { return s.size(); }
1387 };
1388
1389 static constexpr strlen_t strlen;
1390
1394 struct to_upper_t {
1400 std::string operator()(std::string s) const {
1401 for (auto &c : s) c = std::toupper(c);
1402 return s;
1403 }
1404 };
1405
1406 static constexpr to_upper_t to_upper;
1407
1411 struct to_lower_t {
1417 std::string operator()(std::string s) const {
1418 for (auto &c : s) c = std::tolower(c);
1419 return s;
1420 }
1421 };
1422
1423 static constexpr to_lower_t to_lower;
1424
1429 struct trim_t {
1435 std::string operator()(std::string s) const {
1436 auto start = s.find_first_not_of(" \t\n\r\f\v");
1437 if (start == std::string::npos) return "";
1438 auto end = s.find_last_not_of(" \t\n\r\f\v");
1439 return s.substr(start, end - start + 1);
1440 }
1441 };
1442
1443 static constexpr trim_t trim;
1444
1454 std::string operator()(std::string s) const {
1455 std::reverse(s.begin(), s.end());
1456 return s;
1457 }
1458 };
1459
1461
1465 struct size_t_ {
1471 template <class Container>
1472 auto operator()(const Container &c) const -> decltype(c.size()) {
1473 return c.size();
1474 }
1475 };
1476
1477 static constexpr size_t_ size;
1478
1482 struct empty_t {
1488 template <class Container>
1489 bool operator()(const Container &c) const {
1490 return c.empty();
1491 }
1492 };
1493
1494 static constexpr empty_t empty;
1495
1505 template <class Container>
1506 auto operator()(const Container &c) const ->
1507 typename std::decay<decltype(*std::max_element(
1508 c.begin(), c.end()))>::type {
1509 return *std::max_element(c.begin(), c.end());
1510 }
1511 };
1512
1513 static constexpr max_element_t max_element;
1514
1524 template <class Container>
1525 auto operator()(const Container &c) const ->
1526 typename std::decay<decltype(*std::min_element(
1527 c.begin(), c.end()))>::type {
1528 return *std::min_element(c.begin(), c.end());
1529 }
1530 };
1531
1532 static constexpr min_element_t min_element;
1533
1537 struct sum_t {
1543 template <class Range>
1544 auto operator()(Range r) const -> decltype(std::accumulate(
1545 r.begin(), r.end(), typename Range::value_type{})) {
1546 using T = typename Range::value_type;
1547 return std::accumulate(r.begin(), r.end(), T{});
1548 }
1549 };
1550
1551 static constexpr sum_t sum;
1552
1556 struct average_t {
1562 template <class Range>
1563 auto operator()(Range r) const
1564 -> decltype(std::accumulate(r.begin(),
1565 r.end(),
1566 typename Range::value_type{})
1567 / r.size()) {
1568 using T = typename Range::value_type;
1569 return std::accumulate(r.begin(), r.end(), T{}) / r.size();
1570 }
1571 };
1572
1573 static constexpr average_t average;
1574
1579 template <class T>
1580 struct Between {
1582
1588 bool operator()(const T &x) const { return low <= x && x <= high; }
1589 };
1590
1598 template <class T>
1599 Between<T> between(T low, T high) {
1600 return {low, high};
1601 }
1602
1607 template <class T>
1610
1616 bool operator()(const T &x) const { return low < x && x < high; }
1617 };
1618
1626 template <class T>
1628 return {low, high};
1629 }
1630
1635 template <class T>
1638
1644 bool operator()(const T &x) const { return x % n == 0; }
1645 };
1646
1653 template <class T>
1655 return {n};
1656 }
1657
1667 template <class Int>
1668 bool operator()(Int n) const {
1669 return n > 0 && (n & (n - 1)) == 0;
1670 }
1671 };
1672
1674
1684 template <class T>
1685 bool operator()(T n) const {
1686 std::string s = std::to_string(n);
1687 std::string r = s;
1688 std::reverse(r.begin(), r.end());
1689 return s == r;
1690 }
1691 };
1692
1693 static constexpr palindrome_t palindrome;
1694
1704 template <class... Args>
1705 bool operator()(Args &&...) const {
1706 return true;
1707 }
1708 };
1709
1710 static constexpr always_true_t always_true;
1711
1721 template <class... Args>
1722 bool operator()(Args &&...) const {
1723 return false;
1724 }
1725 };
1726
1728
1733 template <class T>
1734 struct Clamp {
1736
1742 T operator()(T x) const { return std::max(low, std::min(high, x)); }
1743 };
1744
1752 template <class T>
1753 Clamp<T> clamp(T low, T high) {
1754 return {low, high};
1755 }
1756
1766 long long operator()() const {
1767 return std::chrono::duration_cast<std::chrono::seconds>(
1768 std::chrono::system_clock::now().time_since_epoch())
1769 .count();
1770 }
1771 };
1772
1773 static constexpr timestamp_t timestamp;
1774
1780 struct plus_t {
1789 template <class T, class U>
1790 auto operator()(T a, U b) const -> decltype(a + b) {
1791 return a + b;
1792 }
1793 };
1794
1795 static constexpr plus_t plus;
1796
1802 struct minus_t {
1811 template <class T, class U>
1812 auto operator()(T a, U b) const -> decltype(a - b) {
1813 return a - b;
1814 }
1815 };
1816
1817 static constexpr minus_t minus;
1818
1833 template <class T, class U>
1834 auto operator()(T a, U b) const -> decltype(a * b) {
1835 return a * b;
1836 }
1837 };
1838
1839 static constexpr multiplies_t multiplies;
1840
1847 struct divides_t {
1856 template <class T, class U>
1857 auto operator()(T a, U b) const -> decltype(a / b) {
1858 return a / b;
1859 }
1860 };
1861
1862 static constexpr divides_t divides;
1863
1870 struct modulus_t {
1879 template <class T, class U>
1880 auto operator()(T a, U b) const -> decltype(a % b) {
1881 return a % b;
1882 }
1883 };
1884
1885 static constexpr modulus_t modulus;
1886
1887 struct is_null_t {
1893 template <class T>
1894 bool operator()(const T &p) const {
1895 return p == nullptr;
1896 }
1897 };
1898
1899 static constexpr is_null_t is_null;
1900
1901 struct not_null_t {
1907 template <class T>
1908 bool operator()(const T &p) const {
1909 return p != nullptr;
1910 }
1911 };
1912
1913 static constexpr not_null_t not_null;
1914
1915 template <size_t N>
1916 struct nth_t {
1922 template <class T>
1923 auto operator()(T &&t) const //
1924 -> typename std::decay<decltype(std::get<N>(
1925 std::forward<T>(t)))>::type {
1926 return std::get<N>(std::forward<T>(t));
1927 }
1928 };
1929
1935 template <size_t N>
1937 return {};
1938 }
1939
1945 template <class Class, class Ret, class... Args>
1946 struct Method {
1947 Ret (Class::*ptr)(Args...);
1948 Params<Args...> param;
1949
1955 Method(Ret (Class::*ptr)(Args...), const Args &...args) :
1956 ptr(ptr), param(args...) {}
1957
1963 template <class T>
1964 Ret operator()(T &&obj) const {
1965 return param.apply(
1966 [&](const Args &...args) { return (obj.*ptr)(args...); });
1967 }
1968
1974 template <class T>
1975 Ret operator()(T *obj) const {
1976 return param.apply(
1977 [&](const Args &...args) { return (obj->*ptr)(args...); });
1978 }
1979 };
1980
1984 template <class Class, class Ret, class... Args>
1985 Method<Class, Ret, Args...>
1986 method(Ret (Class::*ptr)(Args...), const Args &...args) {
1987 return Method<Class, Ret, Args...>{ptr, args...};
1988 }
1989
1994 template <class... Args>
1995 struct Call {
1996 Params<Args...> param;
1997
2002 Call(const Args &...args) : param(args...) {}
2003
2009 template <class F>
2010 auto operator()(F &&f) const -> //
2011 typename std::decay<decltype(param.apply(
2012 std::forward<F>(f)))>::type {
2013 return param.apply(std::forward<F>(f));
2014 }
2015 };
2016
2020 template <class... Args>
2021 Call<Args...> call(const Args &...args) {
2022 return Call<Args...>{args...};
2023 }
2024 }
2025}
表示文件操作错误,如打开失败、读取失败等。
Definition csexc.h:81
生成器模板类,用于创建可迭代的序列生成器。
Definition gen.h:51
std::decay< decltype(true ? std::declval< Gen1::value_type >() :std::declval< Gen2::value_type >())>::type value_type
Definition gen.h:154
递归参数包包装器,将多个参数存储为值类型,并支持通过 apply 方法延迟调用。
Definition params.h:48
ValueError(const std::string &msg)
构造 ValueError。
Definition csexc.h:115
链式生成器,将两个生成器首尾连接。
Definition gextra.h:322
void advance()
向前移动一步。
Definition gextra.h:359
Chain(Gen1 g1, Gen2 g2)
构造函数。
Definition gextra.h:337
Gen1 gen1
Definition gextra.h:328
Gen2 gen2
Definition gextra.h:329
typename std::decay< decltype(true ? std::declval< typename Gen1::value_type >() :std::declval< typename Gen2::value_type >())>:: type T
Definition gextra.h:323
T current()
获取当前值。
Definition gextra.h:349
bool done()
检查生成器是否已完成。
Definition gextra.h:343
分块生成器,将元素按块分组。
Definition gextra.h:248
bool done()
检查生成器是否已完成。
Definition gextra.h:281
size_t chunk_size_
Definition gextra.h:250
std::vector< typename Gen::value_type > current()
获取当前块内容。
Definition gextra.h:290
void init()
Definition gextra.h:254
bool started
Definition gextra.h:252
void advance()
向前移动一步,读取下一个块。
Definition gextra.h:298
Gen gen_
Definition gextra.h:249
Chunk(Gen gen, size_t chunk_size=16)
构造函数。
Definition gextra.h:271
std::vector< typename Gen::value_type > chunk_
Definition gextra.h:251
调试生成器,打印每个元素的值。
Definition gextra.h:413
void advance()
向前移动一步。
Definition gextra.h:449
bool done()
检查生成器是否已完成。
Definition gextra.h:433
Gen gen
Definition gextra.h:414
std::string message
Definition gextra.h:415
Debug(Gen g, std::string msg="Current Value: ", std::ostream &os=std::cout)
构造函数。
Definition gextra.h:425
Gen::value_type current()
获取当前值并打印调试信息。
Definition gextra.h:439
std::ostream & out
Definition gextra.h:416
跳过元素直到谓词成立(跳过第一个满足条件的元素)。
Definition gextra.h:511
auto current() -> decltype(gen.current())
获取当前值。
Definition gextra.h:542
Pred pred
Definition gextra.h:513
Gen gen
Definition gextra.h:512
DropUntil(Gen g, Pred p)
构造函数。
Definition gextra.h:527
bool dropped
Definition gextra.h:514
bool done()
检查生成器是否已完成。
Definition gextra.h:533
void do_drop()
Definition gextra.h:516
void advance()
向前移动一步。
Definition gextra.h:547
文件块生成器,按固定大小读取文件块。
Definition gextra.h:130
bool done()
检查生成器是否已完成。
Definition gextra.h:157
FileChunks(const std::string &filename, size_t chunk_size=1024, std::ios_base::openmode mode=std::ios::in)
构造函数,打开文件并读取第一个数据块。
Definition gextra.h:143
std::string current()
获取当前数据块。
Definition gextra.h:163
std::shared_ptr< std::ifstream > file_
Definition gextra.h:131
std::string current_chunk_
Definition gextra.h:132
size_t chunk_size_
Definition gextra.h:133
void advance()
向前移动一步,读取下一个数据块。
Definition gextra.h:168
文件行生成器,逐行读取文本文件。
Definition gextra.h:90
std::shared_ptr< std::ifstream > file_
Definition gextra.h:91
FileLines(const std::string &filename)
构造函数,打开文件并读取第一行。
Definition gextra.h:100
bool done()
检查生成器是否已完成。
Definition gextra.h:111
std::string current_line_
Definition gextra.h:92
void advance()
向前移动一步,读取下一行。
Definition gextra.h:122
std::string current()
获取当前行内容。
Definition gextra.h:117
Pipeline(Op o, Rest... r)
构造函数。
Definition gextra.h:602
Pipeline< Rest... > rest
剩余适配器组成的管道。
Definition gextra.h:594
Op op
第一个适配器对象。
Definition gextra.h:593
auto operator()(Gen gen) const -> decltype(rest(gen|op))
将管道应用到生成器。
Definition gextra.h:611
Pipeline(Op o)
构造函数。
Definition gextra.h:572
Op op
存储的适配器对象。
Definition gextra.h:565
auto operator()(Gen gen) const -> decltype(gen|op)
将管道应用到生成器。
Definition gextra.h:581
管道类模板,用于组合多个适配器。
Definition gextra.h:557
随机数生成器,生成指定范围内的随机数。
Definition gextra.h:52
Random(T min, T max, std::mt19937::result_type seed=std::random_device{}())
构造函数。
Definition gextra.h:64
void advance()
向前移动一步。
Definition gextra.h:84
bool done()
检查生成器是否已完成。
Definition gextra.h:73
T current()
获取当前随机数。
Definition gextra.h:79
uniform_distribution_t< T > dist_
Definition gextra.h:54
T curr_
Definition gextra.h:55
std::mt19937 gen_
Definition gextra.h:53
Definition gextra.h:672
T current()
Definition gextra.h:693
bool done()
Definition gextra.h:688
BinaryOp op
Definition gextra.h:675
Gen gen
Definition gextra.h:673
Scan(Gen g, T init, BinaryOp o)
Definition gextra.h:686
void lazy_init()
Definition gextra.h:678
void advance()
Definition gextra.h:698
T state
Definition gextra.h:674
bool started
Definition gextra.h:676
步进生成器,按指定步长跳过元素。
Definition gextra.h:372
bool done()
检查生成器是否已完成。
Definition gextra.h:392
size_t step
Definition gextra.h:374
Gen gen
Definition gextra.h:373
void advance()
向前移动一步,跳过step-1个元素。
Definition gextra.h:403
StepBy(Gen g, size_t s=1)
构造函数。
Definition gextra.h:383
Gen::value_type current()
获取当前值。
Definition gextra.h:398
取元素直到谓词成立(包含第一个满足条件的元素)。
Definition gextra.h:459
Pred pred
Definition gextra.h:461
bool stopped
Definition gextra.h:462
bool done()
检查生成器是否已完成。
Definition gextra.h:484
TakeUntil(Gen g, Pred p)
构造函数。
Definition gextra.h:478
Gen gen
Definition gextra.h:460
void try_advance()
Definition gextra.h:464
auto current() -> decltype(gen.current())
获取当前值。
Definition gextra.h:493
void advance()
向前移动一步。
Definition gextra.h:498
滑动窗口生成器,生成固定大小的滑动窗口。
Definition gextra.h:181
void advance()
向前移动一步,滑动窗口。
Definition gextra.h:231
Window(Gen gen, size_t window_size=16)
构造函数。
Definition gextra.h:204
bool done()
检查生成器是否已完成。
Definition gextra.h:214
size_t window_size_
Definition gextra.h:183
Gen gen_
Definition gextra.h:182
std::vector< typename Gen::value_type > current()
获取当前窗口内容。
Definition gextra.h:223
void init()
Definition gextra.h:187
bool started
Definition gextra.h:185
std::vector< typename Gen::value_type > window_
Definition gextra.h:184
创建一个算法适配器。
Definition gextra.h:1094
friend auto operator|(Gen gen, algorithm_t alg) -> decltype(std::declval< F >()(gen.begin(), gen.end(), std::declval< Args >()...))
管道操作符。
Definition gextra.h:1115
F func
Definition gextra.h:1095
algorithm_t(F func, const Args &...args)
构造函数。
Definition gextra.h:1104
Params< Args... > params
Definition gextra.h:1096
分块适配器(用于管道操作符)。
Definition gextra.h:782
chunk_t(size_t size=16)
构造函数。
Definition gextra.h:790
size_t s
Definition gextra.h:783
friend Chunk< Gen > operator|(Gen g, chunk_t t)
管道操作符,创建分块生成器。
Definition gextra.h:800
调试适配器(用于管道操作符)。
Definition gextra.h:892
friend Debug< Gen > operator|(Gen g, debug_t d)
管道操作符,创建调试生成器。
Definition gextra.h:913
debug_t(std::string msg="DEBUG: ", std::ostream &os=std::cout)
构造函数。
Definition gextra.h:902
std::string message
Definition gextra.h:893
std::ostream & out
Definition gextra.h:894
跳过元素直到谓词成立适配器(用于管道操作符)。
Definition gextra.h:973
drop_until_t(Pred p)
构造函数。
Definition gextra.h:981
friend DropUntil< Gen, Pred > operator|(Gen g, drop_until_t du)
管道操作符,创建DropUntil生成器。
Definition gextra.h:991
Pred pred
Definition gextra.h:974
归约适配器,将生成器所有元素归约为单个值。
Definition gextra.h:1013
friend T operator|(Gen gen, reduce_t r)
管道操作符,执行归约。
Definition gextra.h:1032
BinaryOp op_
Definition gextra.h:1015
T init_
Definition gextra.h:1014
reduce_t(T init, BinaryOp op)
构造函数。
Definition gextra.h:1023
Definition gextra.h:1050
scan_t(const T &init, BinaryOp op)
构造函数。
Definition gextra.h:1060
friend Scan< Gen, T, BinaryOp > operator|(Gen gen, scan_t< T, BinaryOp > scan)
将扫描适配器应用到生成器。
Definition gextra.h:1070
BinaryOp op
Definition gextra.h:1052
T state
Definition gextra.h:1051
步进适配器(用于管道操作符)。
Definition gextra.h:857
friend StepBy< Gen > operator|(Gen g, step_by_t s)
管道操作符,创建步进生成器。
Definition gextra.h:875
size_t s
Definition gextra.h:858
step_by_t(size_t size=1)
构造函数。
Definition gextra.h:865
取元素直到谓词成立适配器(用于管道操作符)。
Definition gextra.h:934
friend TakeUntil< Gen, Pred > operator|(Gen g, take_until_t tu)
管道操作符,创建TakeUntil生成器。
Definition gextra.h:952
Pred pred
Definition gextra.h:935
take_until_t(Pred p)
构造函数。
Definition gextra.h:942
窗口适配器(用于管道操作符)。
Definition gextra.h:747
friend Window< Gen > operator|(Gen g, window_t w)
管道操作符,创建窗口生成器。
Definition gextra.h:765
size_t s
Definition gextra.h:748
window_t(size_t size=16)
构造函数。
Definition gextra.h:755
生成器模式头文件。
void seed(T seed)
修改 thread_rng 提供的随机数引擎的种子。
Definition random.h:68
typename uniform_distribution_impl< T >::type uniform_distribution_t
取得对印类型所对应的均匀分布。
Definition sfinae.h:328
Definition algorithm.h:27
Definition gen.h:237
chunk_t chunk(size_t size=16)
创建分块适配器。
Definition gextra.h:810
FileLines file_lines(const std::string &filename)
创建文件行生成器。
Definition gextra.h:727
Chain< Gen1, Gen2 > chain(Gen1 g1, Gen2 g2)
创建链式生成器,将两个生成器首尾连接。
Definition gextra.h:823
step_by_t step_by(size_t size=1)
创建步进适配器。
Definition gextra.h:885
debug_t debug(std::string msg="DEBUG: ", std::ostream &os=std::cout)
创建调试适配器。
Definition gextra.h:925
reduce_t< T, BinaryOp > reduce(const T &init, BinaryOp bo)
创建归约适配器。
Definition gextra.h:1045
window_t window(size_t size=16)
创建窗口适配器。
Definition gextra.h:775
take_until_t< Pred > take_until(Pred p)
创建取元素直到谓词成立适配器。
Definition gextra.h:964
pipeline_t< Ops... > pipeline(Ops... ops)
创建管道适配器。
Definition gextra.h:653
algorithm_t< T, Args... > algorithm(T func, const Args &...args)
创建算法适配器。
Definition gextra.h:1136
drop_until_t< Pred > drop_until(Pred p)
创建跳过元素直到谓词成立适配器。
Definition gextra.h:1003
auto operator|(Gen gen, pipeline_t< Ops... > pl) -> decltype(pl.pipeline(gen))
管道操作符,将管道应用到生成器。
Definition gextra.h:640
FileChunks file_chunks(const std::string &filename, size_t chunk_size=1024, std::ios_base::openmode mode=std::ios::in)
创建文件块生成器。
Definition gextra.h:738
Chain< Gen1, Gen2 > operator+(Gen1 g1, Gen2 g2)
加号操作符重载,用于连接两个生成器。
Definition gextra.h:850
pipeline_t< Op1, Op2 > operator%(Op1 op1, Op2 op2)
管道组合操作符,用于连接两个适配器。
Definition gextra.h:667
Random< T > random(T min, T max, std::mt19937::result_type seed=std::random_device{}())
创建随机数生成器。
Definition gextra.h:716
scan_t< T, BinaryOp > scan(T init, BinaryOp op)
创建一个扫描适配器。
Definition gextra.h:1084
Definition gen.h:1395
static constexpr is_null_t is_null
Definition gextra.h:1899
static constexpr always_false_t always_false
Definition gextra.h:1727
Between< T > between(T low, T high)
创建闭区间谓词。
Definition gextra.h:1599
Method< Class, Ret, Args... > method(Ret(Class::*ptr)(Args...), const Args &...args)
创建成员函数调用器。
Definition gextra.h:1986
static constexpr max_element_t max_element
Definition gextra.h:1513
static constexpr acos_t acos
Definition gextra.h:1289
static constexpr asin_t asin
Definition gextra.h:1272
BetweenExclusive< T > between_exclusive(T low, T high)
创建开区间谓词。
Definition gextra.h:1627
static constexpr power_of_two_t power_of_two
Definition gextra.h:1673
static constexpr average_t average
Definition gextra.h:1573
static constexpr modulus_t modulus
Definition gextra.h:1885
static constexpr log10_t log10
Definition gextra.h:1204
static constexpr min_element_t min_element
Definition gextra.h:1532
static constexpr ceil_t ceil
Definition gextra.h:1358
static constexpr sign_t sign
Definition gextra.h:1324
static constexpr divides_t divides
Definition gextra.h:1862
static constexpr reverse_string_t reverse_string
Definition gextra.h:1460
static constexpr floor_t floor
Definition gextra.h:1375
static constexpr atan_t atan
Definition gextra.h:1306
Call< Args... > call(const Args &...args)
创建函数调用器。
Definition gextra.h:2021
static constexpr multiplies_t multiplies
Definition gextra.h:1839
static constexpr timestamp_t timestamp
Definition gextra.h:1773
static constexpr cos_t cos
Definition gextra.h:1238
static constexpr tan_t tan
Definition gextra.h:1255
static constexpr sum_t sum
Definition gextra.h:1551
static constexpr palindrome_t palindrome
Definition gextra.h:1693
static constexpr minus_t minus
Definition gextra.h:1817
Pow< T > pow(T exp)
创建幂运算变换器。
Definition gextra.h:1168
static constexpr plus_t plus
Definition gextra.h:1795
static constexpr size_t_ size
Definition gextra.h:1477
static constexpr strlen_t strlen
Definition gextra.h:1389
DivisibleBy< T > divisible_by(T n)
创建整除谓词。
Definition gextra.h:1654
static constexpr sin_t sin
Definition gextra.h:1221
static constexpr to_upper_t to_upper
Definition gextra.h:1406
static constexpr trim_t trim
Definition gextra.h:1443
static constexpr to_lower_t to_lower
Definition gextra.h:1423
Clamp< T > clamp(T low, T high)
创建限幅变换器。
Definition gextra.h:1753
static constexpr empty_t empty
Definition gextra.h:1494
static constexpr always_true_t always_true
Definition gextra.h:1710
static constexpr not_null_t not_null
Definition gextra.h:1913
static constexpr round_t round
Definition gextra.h:1341
nth_t< N > nth()
获取 tuple/pair/array 的第 N 个元素的函数。
Definition gextra.h:1936
static constexpr exp_t exp
Definition gextra.h:1187
本库所有组件所在的顶层命名空间。
T min(const MultiArray< T, Dims... > &a)
求最小值。
Definition multiarray.h:1676
T max(const MultiArray< T, Dims... > &a)
求最大值。
Definition multiarray.h:1685
@ T
Definition kb.h:99
提供参数包包装器(Params)和便捷构造函数(params),用于将多个参数打包并支持延迟应用。
提供编译期类型特征检测(SFINAE 工具), 用于判断容器、可调用对象、迭代器、下标访问、字符串、可打印类型、字符类型等。
管道适配器类,用于支持管道操作符。
Definition gextra.h:622
pipeline_t(Ops... ops)
构造函数。
Definition gextra.h:629
Pipeline< Ops... > pipeline
内部管道对象。
Definition gextra.h:623
区间谓词(开区间)。
Definition gextra.h:1608
T high
Definition gextra.h:1609
T low
Definition gextra.h:1609
bool operator()(const T &x) const
判断输入值是否在开区间 (low, high) 内。
Definition gextra.h:1616
区间谓词(闭区间)。
Definition gextra.h:1580
T high
Definition gextra.h:1581
T low
Definition gextra.h:1581
bool operator()(const T &x) const
判断输入值是否在闭区间 [low, high] 内。
Definition gextra.h:1588
函数调用变化器。
Definition gextra.h:1995
auto operator()(F &&f) const -> typename std::decay< decltype(param.apply(std::forward< F >(f)))>::type
调用函数。
Definition gextra.h:2010
Call(const Args &...args)
构造函数。
Definition gextra.h:2002
Params< Args... > param
参数包
Definition gextra.h:1996
限幅变换器。
Definition gextra.h:1734
T low
Definition gextra.h:1735
T operator()(T x) const
将输入值限制在 [low, high] 范围内。
Definition gextra.h:1742
T high
Definition gextra.h:1735
整除谓词。
Definition gextra.h:1636
bool operator()(const T &x) const
判断输入值是否能被 n 整除。
Definition gextra.h:1644
T n
Definition gextra.h:1637
成员函数调用变换器。
Definition gextra.h:1946
Params< Args... > param
参数包
Definition gextra.h:1948
Ret(Class::*) ptr(Args...)
成员函数指针
Definition gextra.h:1947
Method(Ret(Class::*ptr)(Args...), const Args &...args)
构造函数。
Definition gextra.h:1955
Ret operator()(T &&obj) const
调用对象的成员函数。
Definition gextra.h:1964
Ret operator()(T *obj) const
从指针调用对象的成员函数。
Definition gextra.h:1975
幂运算变换器。
Definition gextra.h:1147
T exponent
Definition gextra.h:1148
auto operator()(U x) const -> decltype(std::pow(x, exponent))
计算输入值的指定次幂。
Definition gextra.h:1156
反余弦变换器。
Definition gextra.h:1277
auto operator()(T x) const -> decltype(std::acos(x))
计算输入值的反余弦值。
Definition gextra.h:1284
恒假谓词。
Definition gextra.h:1715
bool operator()(Args &&...) const
对任意输入返回 false。
Definition gextra.h:1722
恒真谓词。
Definition gextra.h:1698
bool operator()(Args &&...) const
对任意输入返回 true。
Definition gextra.h:1705
反正弦变换器。
Definition gextra.h:1260
auto operator()(T x) const -> decltype(std::asin(x))
计算输入值的反正弦值。
Definition gextra.h:1267
反正切变换器。
Definition gextra.h:1294
auto operator()(T x) const -> decltype(std::atan(x))
计算输入值的反正切值。
Definition gextra.h:1301
范围平均值变换器。
Definition gextra.h:1556
auto operator()(Range r) const -> decltype(std::accumulate(r.begin(), r.end(), typename Range::value_type{})/r.size())
计算范围中所有元素的平均值。
Definition gextra.h:1563
向上取整变换器。
Definition gextra.h:1346
auto operator()(T x) const -> decltype(std::ceil(x))
对输入值进行向上取整。
Definition gextra.h:1353
余弦变换器。
Definition gextra.h:1226
auto operator()(T x) const -> decltype(std::cos(x))
计算输入值的余弦值。
Definition gextra.h:1233
除法函数子。
Definition gextra.h:1847
auto operator()(T a, U b) const -> decltype(a/b)
对两个值执行除法。
Definition gextra.h:1857
容器判空谓词。
Definition gextra.h:1482
bool operator()(const Container &c) const
判断容器是否为空。
Definition gextra.h:1489
自然指数变换器。
Definition gextra.h:1175
auto operator()(T x) const -> decltype(std::exp(x))
计算输入值的自然指数。
Definition gextra.h:1182
向下取整变换器。
Definition gextra.h:1363
auto operator()(T x) const -> decltype(std::floor(x))
对输入值进行向下取整。
Definition gextra.h:1370
Definition gextra.h:1887
bool operator()(const T &p) const
判断指针是否非空。
Definition gextra.h:1894
常用对数变换器(以10为底)。
Definition gextra.h:1192
auto operator()(T x) const -> decltype(std::log10(x))
计算输入值的常用对数。
Definition gextra.h:1199
容器最大值变换器。
Definition gextra.h:1499
auto operator()(const Container &c) const -> typename std::decay< decltype(*std::max_element(c.begin(), c.end()))>::type
获取容器中的最大值。
Definition gextra.h:1506
容器最小值变换器。
Definition gextra.h:1518
auto operator()(const Container &c) const -> typename std::decay< decltype(*std::min_element(c.begin(), c.end()))>::type
获取容器中的最小值。
Definition gextra.h:1525
减法函数子。
Definition gextra.h:1802
auto operator()(T a, U b) const -> decltype(a - b)
对两个值执行减法。
Definition gextra.h:1812
取模函数子。
Definition gextra.h:1870
auto operator()(T a, U b) const -> decltype(a % b)
对两个值执行取模。
Definition gextra.h:1880
乘法函数子。
Definition gextra.h:1824
auto operator()(T a, U b) const -> decltype(a *b)
对两个值执行乘法。
Definition gextra.h:1834
Definition gextra.h:1901
bool operator()(const T &p) const
判断指针是否非空。
Definition gextra.h:1908
Definition gextra.h:1916
auto operator()(T &&t) const -> typename std::decay< decltype(std::get< N >(std::forward< T >(t)))>::type
获取 tuple/pair/array 的第 N 个元素。
Definition gextra.h:1923
回文数谓词。
Definition gextra.h:1678
bool operator()(T n) const
判断输入值是否为回文数。
Definition gextra.h:1685
加法函数子。
Definition gextra.h:1780
auto operator()(T a, U b) const -> decltype(a+b)
对两个值执行加法。
Definition gextra.h:1790
2的幂次谓词。
Definition gextra.h:1661
bool operator()(Int n) const
判断输入值是否为2的幂次。
Definition gextra.h:1668
字符串反转变换器。
Definition gextra.h:1448
std::string operator()(std::string s) const
反转字符串。
Definition gextra.h:1454
四舍五入变换器。
Definition gextra.h:1329
auto operator()(T x) const -> decltype(std::round(x))
对输入值进行四舍五入。
Definition gextra.h:1336
符号变换器。
Definition gextra.h:1312
int operator()(T x) const
计算输入值的符号。
Definition gextra.h:1319
正弦变换器。
Definition gextra.h:1209
auto operator()(T x) const -> decltype(std::sin(x))
计算输入值的正弦值。
Definition gextra.h:1216
容器大小变换器。
Definition gextra.h:1465
auto operator()(const Container &c) const -> decltype(c.size())
获取容器的大小。
Definition gextra.h:1472
字符串长度变换器。
Definition gextra.h:1380
size_t operator()(const std::string &s) const
获取字符串的长度。
Definition gextra.h:1386
范围求和变换器。
Definition gextra.h:1537
auto operator()(Range r) const -> decltype(std::accumulate(r.begin(), r.end(), typename Range::value_type{}))
计算范围中所有元素的和。
Definition gextra.h:1544
正切变换器。
Definition gextra.h:1243
auto operator()(T x) const -> decltype(std::tan(x))
计算输入值的正切值。
Definition gextra.h:1250
时间戳生成器。
Definition gextra.h:1761
long long operator()() const
获取当前时间的 Unix 时间戳。
Definition gextra.h:1766
字符串转小写变换器。
Definition gextra.h:1411
std::string operator()(std::string s) const
将字符串转换为小写。
Definition gextra.h:1417
字符串转大写变换器。
Definition gextra.h:1394
std::string operator()(std::string s) const
将字符串转换为大写。
Definition gextra.h:1400
字符串去空格变换器。
Definition gextra.h:1429
std::string operator()(std::string s) const
去除字符串首尾的空白字符。
Definition gextra.h:1435