forked from skyfireitdiy/sflib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsf_range.h
104 lines (83 loc) · 2.03 KB
/
sf_range.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
* @version 1.0.0
* @author skyfire
* @mail [email protected]
* @see http://github.com/skyfireitdiy/sflib
* @file sf_range.h
* sflib第一版本发布
* 版本号1.0.0
* 发布日期:2018-10-22
*/
/*
* sf_range range产生序列的功能
*/
#pragma once
#include <stdexcept>
namespace skyfire
{
template<typename T>
class sf_range_iteator__
{
public:
using value_type = T;
using size_type = size_t;
private:
size_type cursor__;
const value_type step__;
value_type value__;
public:
sf_range_iteator__(size_type start,const value_type& value,const value_type& step);
value_type operator*()const;
bool operator!=(const sf_range_iteator__<T>& other) const;
sf_range_iteator__<T> & operator ++();
};
template<typename T>
class sf_range_impl__
{
public:
using value_type = T;
using reference = const T &;
using const_reference = const T &;
using iterator = const sf_range_iteator__<T>;
using const_iterator = const sf_range_iteator__<T>;
using size_type = typename sf_range_iteator__<T>::size_type;
private:
const value_type begin__;
const value_type end__;
const value_type step__;
const size_type max_count__;
size_type get_max_count__() const;
public:
sf_range_impl__(const value_type vbegin, const value_type vend, const value_type vstep);
size_type size()const;
const_iterator begin()const;
const_iterator end()const;
};
/**
* 生成range序列
* @tparam T 类型
* @param end 结尾值
* @return range序列
*/
template<typename T>
sf_range_impl__<T> sf_range(const T &end);
/**
* 生成range序列
* @tparam T 类型
* @param begin 开始值
* @param end 结尾值
* @return range序列
*/
template<typename T>
sf_range_impl__<T> sf_range(const T &begin, const T &end);
/**
* 生成range序列
* @tparam T 类型
* @param begin 开始值
* @param end 结尾值
* @param step 步进
* @return range序列
*/
template<typename T>
auto sf_range(const T &begin, const T &end, const T &step);
}