Console Library 8.0.0
A header-only library that makes C++ simple
Loading...
Searching...
No Matches
gen.h File Reference

生成器模式头文件。 More...

#include <cmath>
#include <cstdlib>
#include <iterator>
#include <type_traits>
#include <utility>
#include <vector>
#include "../core/csexc.h"
#include "../text/repr.h"
#include "./iter.h"

Go to the source code of this file.

Classes

class  console::Generator< Derived, T >
 生成器模板类,用于创建可迭代的序列生成器。 More...
class  console::Generator< Derived, T >::iterator
 生成器迭代器类,实现输入迭代器接口。 More...
class  console::gen::Views< Iter >
 迭代器范围生成器,生成从begin到end的值。 More...
class  console::gen::List< T >
 用书数据的序列,从初始化列表构造。 More...
class  console::gen::Range< T >
 范围生成器,生成从start到end的等差数列。 More...
class  console::gen::Repeat< T >
 重复生成器,重复生成同一个值指定次数。 More...
class  console::gen::Cycle< T >
 循环生成器,无限循环遍历给定列表。 More...
class  console::gen::Counter< T >
 计数器生成器,生成递增或递减的序列。 More...
class  console::gen::Map< Gen, Func >
 映射生成器,对源生成器的每个元素应用函数。 More...
class  console::gen::Filter< Gen, Pred >
 过滤生成器,只保留满足谓词的元素。 More...
class  console::gen::Take< Gen >
 取前n个元素的生成器适配器。 More...
class  console::gen::Drop< Gen >
 跳过前n个元素的生成器适配器。 More...
class  console::gen::Enumerate< Gen >
 枚举生成器,为每个元素附加索引。 More...
class  console::gen::Generate< Func >
 生成器,通过反复调用函数生成无限序列。 More...
class  console::gen::Zip< Gen1, Gen2 >
 压缩生成器,将两个生成器的元素配对输出。 More...
class  console::gen::TakeWhile< Gen, Pred >
 取得前若干个元素直到谓词不成立。 More...
class  console::gen::DropWhile< Gen, Pred >
 跳过前若干个元素直到谓词不成立。 More...
class  console::gen::map_t< Func >
 映射适配器(用于管道操作符)。 More...
class  console::gen::filter_t< Pred >
 过滤适配器(用于管道操作符)。 More...
class  console::gen::take_t
 取前n个元素适配器(用于管道操作符)。 More...
class  console::gen::drop_t
 跳过前n个元素适配器(用于管道操作符)。 More...
class  console::gen::enumerate_t
 枚举生成器,为每个元素附加索引。 More...
class  console::gen::take_while_t< Pred >
 取前若干个元素适配器(用于管道操作符)。 More...
class  console::gen::drop_while_t< Pred >
 跳过前若干个元素适配器(用于管道操作符)。 More...
class  console::gen::collect< Container >
 容器收集适配器。 More...
class  console::gen::to_t< Iterator >
 创建目标迭代器适配器。 More...
struct  console::ops::Add< T >
 加固定值变换器。 More...
struct  console::ops::Sub< T >
 减固定值变换器。 More...
struct  console::ops::Mul< T >
 乘固定值变换器。 More...
struct  console::ops::Div< T >
 除固定值变换器。 More...
struct  console::ops::Mod< T >
 取模固定值变换器。 More...
struct  console::ops::inc_t
 自增变换器。 More...
struct  console::ops::dec_t
 自减变换器。 More...
struct  console::ops::negate_t
 取负变换器。 More...
struct  console::ops::square_t
 平方变换器。 More...
struct  console::ops::cube_t
 立方变换器。 More...
struct  console::ops::sqrt_t
 平方根变换器。 More...
struct  console::ops::reciprocal_t
 倒数变换器。 More...
struct  console::ops::abs_t
 绝对值变换器。 More...
struct  console::ops::to_string_t
 转为字符串变换器。 More...
struct  console::ops::Gt< T >
 大于谓词。 More...
struct  console::ops::Ge< T >
 大于等于谓词。 More...
struct  console::ops::Lt< T >
 小于谓词。 More...
struct  console::ops::Le< T >
 小于等于谓词。 More...
struct  console::ops::Eq< T >
 等于谓词。 More...
struct  console::ops::Ne< T >
 不等于谓词。 More...
struct  console::ops::even_t
 偶数谓词。 More...
struct  console::ops::odd_t
 奇数谓词。 More...
struct  console::ops::positive_t
 正数谓词。 More...
struct  console::ops::negative_t
 负数谓词。 More...
struct  console::ops::zero_t
 零谓词。 More...
struct  console::ops::prime_t
 素数谓词。 More...
struct  console::ops::And< P, Q >
 逻辑与组合器。 More...
struct  console::ops::Or< P, Q >
 逻辑或组合器。 More...
struct  console::ops::Not< P >
 逻辑非组合器。 More...
struct  console::ops::Member< Class, Mem >
 取成员变量变换器。 More...
struct  console::ops::first_t
 取 pair 的 first 变换器。 More...
struct  console::ops::second_t
 取 pair 的 second 变换器。 More...
struct  console::ops::unique< T >
 相邻去重过滤器。 More...
struct  console::ops::identity_t
 恒等变换器。 More...
struct  console::ops::as< T >
 转型变化器。 More...
struct  console::ops::Compose< F, G >
 函数组合器,将两个函数组合为一个函数。 More...

Namespaces

namespace  console
 本库所有组件所在的顶层命名空间。
namespace  console::gen
namespace  console::ops

Functions

template<class Derived, class T>
Generator< Derived, T >::iterator console::iter (Generator< Derived, T > &g)
 获取生成器迭代器的辅助函数。
template<class Derived, class T>
T console::next (typename Generator< Derived, T >::iterator &it)
 从迭代器获取下一个值的辅助函数。
template<class Derived, class T, class CharT = char, class Traits = std::char_traits<CharT>>
std::basic_ostream< CharT, Traits > & console::print_generator (std::basic_ostream< CharT, Traits > &os, const Generator< Derived, T > &gen)
 将 Generator 的内容输出到流,格式为 [elem1, elem2, ...]。
template<class Derived, class T, class CharT = char, class Traits = std::char_traits<CharT>>
std::basic_ostream< CharT, Traits > & console::operator<< (std::basic_ostream< CharT, Traits > &os, const Generator< Derived, T > &gen)
 输出 Generator 到流的 operator<< 重载。
template<class Iter>
Views< Iter > console::gen::views (Iter begin, Iter end)
 从迭代器范围创建视图生成器。
template<class Container>
Views< typename Container::iterator > console::gen::views (Container &container)
 从容器引用创建视图生成器。
template<class T>
List< T > console::gen::list (std::initializer_list< T > list)
 从初始化列表创建列表生成器。
template<class Iterator>
List< typename std::decay< typename Iterator::value_type >::type > console::gen::list (Iterator begin, Iterator end)
 从迭代器范围创建列表生成器。
template<class Container>
List< typename Container::value_type > console::gen::list (Container &container)
 从容器引用创建列表生成器。
template<class T>
Range< T > console::gen::range (T begin, T end, T step=1)
 创建范围生成器。
template<class T>
Range< T > console::gen::range (T end)
 创建范围生成器。
template<class T>
Repeat< T > console::gen::repeat (T val, size_t n)
 创建重复生成器。
template<class T>
Repeat< T > console::gen::repeat (T val)
 创建重复生成器。
template<class T>
Cycle< T > console::gen::cycle (std::initializer_list< T > list)
 创建循环生成器。
template<class Iterator>
Cycle< typename std::decay< typename Iterator::value_type >::type > console::gen::cycle (Iterator begin, Iterator end)
 创建循环生成器。
template<class Container>
Cycle< typename Container::value_type > console::gen::cycle (const Container &container)
 创建循环生成器。
template<class T>
Counter< T > console::gen::counter (T start=T{0}, T step=T{1}, size_t times=size_t(-1))
 创建计数器生成器。
template<class Func>
map_t< Func > console::gen::map (Func f)
 创建映射适配器。
template<class Pred>
filter_t< Pred > console::gen::filter (Pred pred)
 创建过滤适配器。
take_t console::gen::take (size_t n)
 创建取前n个元素适配器。
drop_t console::gen::drop (size_t n)
 创建跳过前n个元素适配器。
template<class Func>
Generate< Func > console::gen::generate (Func func)
 创建生成器适配器。
template<class Gen1, class Gen2>
Zip< typename std::decay< Gen1 >::type, typename std::decay< Gen2 >::type > console::gen::zip (Gen1 &&g1, Gen2 &&g2)
 压缩两个生成器。
template<class Pred>
take_while_t< Pred > console::gen::take_while (Pred pred)
 创建取前若干个元素适配器。
template<class Pred>
drop_while_t< Pred > console::gen::drop_while (Pred pred)
 创建跳过前若干个元素适配器。
template<class Iterator>
to_t< Iterator > console::gen::to (Iterator it)
 创建目标迭代器适配器。
template<class Gen1, class Gen2>
auto console::gen::operator& (Gen1 &&g1, Gen2 &&g2) -> decltype(gen::zip(std::forward< Gen1 >(g1), std::forward< Gen2 >(g2)))
 按位与操作符重载,用于压缩两个生成器。
template<class T>
Add< T > console::ops::add (T v)
 创建加固定值变换器。
template<class T>
Sub< T > console::ops::sub (T v)
 创建减固定值变换器。
template<class T>
Mul< T > console::ops::mul (T v)
 创建乘固定值变换器。
template<class T>
Div< T > console::ops::div (T v)
 创建除固定值变换器。
template<class T>
Mod< T > console::ops::mod (T v)
 创建取模固定值变换器。
template<class T>
Gt< T > console::ops::gt (T t)
 创建大于谓词。
template<class T>
Ge< T > console::ops::ge (T t)
 创建大于等于谓词。
template<class T>
Lt< T > console::ops::lt (T t)
 创建小于谓词。
template<class T>
Le< T > console::ops::le (T t)
 创建小于等于谓词。
template<class T>
Eq< T > console::ops::eq (T v)
 创建等于谓词。
template<class T>
Ne< T > console::ops::ne (T v)
 创建不等于谓词。
template<class P, typename Q>
And< P, Q > console::ops::and_ (P p, Q q)
 创建逻辑与组合谓词。
template<class P, typename Q>
Or< P, Q > console::ops::or_ (P p, Q q)
 创建逻辑或组合谓词。
template<class P>
Not< P > console::ops::not_ (P p)
 创建逻辑非组合谓词。
template<class Class, typename Mem>
Member< Class, Mem > console::ops::member (Mem Class::*p)
 创建成员变量访问器。
template<class P, class Q>
And< P, Q > console::ops::operator&& (P p, Q q)
 逻辑与运算符,等价于 and_(p, q)。
template<class P, class Q>
Or< P, Q > console::ops::operator|| (P p, Q q)
 逻辑或运算符,等价于 or_(p, q)。
template<class P>
Not< P > console::ops::operator! (P p)
 逻辑非运算符,等价于 not_(p)。
template<class F, class G>
Compose< F, G > console::ops::compose (F f, G g)
 将两个函数组合为一个函数。
template<class F, class... Rest>
auto console::ops::compose (F f, Rest... rest) -> Compose< F, decltype(compose(rest...))>
 将多个函数组合为一个函数。
template<class F, class G>
Compose< F, G > console::ops::operator>> (F f, G g)
 函数组合运算符,将两个函数组合为一个函数。

Variables

static constexpr enumerate_t console::gen::enumerate
static constexpr inc_t console::ops::inc
static constexpr dec_t console::ops::dec
static constexpr negate_t console::ops::negate
static constexpr square_t console::ops::square
static constexpr cube_t console::ops::cube
static constexpr sqrt_t console::ops::sqrt
static constexpr reciprocal_t console::ops::reciprocal
static constexpr abs_t console::ops::abs
static constexpr to_string_t console::ops::to_string
static constexpr even_t console::ops::even
static constexpr odd_t console::ops::odd
static constexpr positive_t console::ops::positive
static constexpr negative_t console::ops::negative
static constexpr zero_t console::ops::zero
static constexpr prime_t console::ops::prime
static constexpr first_t console::ops::first
static constexpr second_t console::ops::second
static constexpr identity_t console::ops::identity

Detailed Description

生成器模式头文件。

提供生成器模式的模板类实现,包含多种预定义的生成器和迭代器适配器。

Author
MrXie1109
Date
2026