YSTest: integer_sequence.hpp 源文件

YSTest PreAlpha_b700_20160611 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

integer_sequence.hpp
浏览该文件的文档.
1 /*
2 © 2012-2013, 2015-2016 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #ifndef YB_INC_ystdex_sequence_hpp_
29 #define YB_INC_ystdex_sequence_hpp_ 1
30
31 #include "variadic.hpp" // for "variadic.hpp", empty_base, vseq::defer_i, _t,
32 // common_type_t;
33
34 namespace ystdex
35 {
36
37 inline namespace cpp2014
38 {
39
46 #if __cpp_lib_integer_sequence >= 201304 || __cplusplus > 201103L
47 using std::integer_sequence;
48 using std::index_sequence;
49 #else
50 template<typename _tInt, _tInt... _vSeq>
51 struct integer_sequence
52 {
53 using value_type = _tInt;
54
55 static yconstfn size_t
56 size() ynoexcept
57 {
58 return sizeof...(_vSeq);
59 }
60 };
61
62 template<size_t... _vSeq>
63 using index_sequence = integer_sequence<size_t, _vSeq...>;
64 #endif
65
66
67 } // inline namespace cpp2014;
68
69
71
72 namespace vseq
73 {
74
76
77 template<class _tSeq, size_t... _vIdxSeq>
78 struct project<_tSeq, index_sequence<_vIdxSeq...>, enable_for_instances<_tSeq>>
79 {
80 using type = instance_apply_t<_tSeq,
81 empty_base<at_t<params_of_t<_tSeq>, _vIdxSeq>...>>;
82 };
83
84
86 template<typename _tInt>
87 struct bound_integer_sequence
88 {
89 template<typename... _types>
90 using apply = identity<integer_sequence<_tInt, _types::value...>>;
91 };
92
93
94 template<typename _tInt, _tInt... _vSeq>
95 struct ctor_of<integer_sequence<_tInt, _vSeq...>>
96 {
97 using type = bound_integer_sequence<_tInt>;
98 };
99
100
101 template<typename _tInt, _tInt... _vSeq>
102 struct params_of<integer_sequence<_tInt, _vSeq...>>
103 {
104 using type = empty_base<integral_constant<_tInt, _vSeq>...>;
105 };
107
108
109 template<typename _tInt, _tInt... _vSeq1, _tInt... _vSeq2>
110 struct vec_add<integer_sequence<_tInt, _vSeq1...>,
111 integer_sequence<_tInt, _vSeq2...>>
112 {
113 using type = integer_sequence<_tInt, (_vSeq1 + _vSeq2)...>;
114 };
115
116
117 template<typename _tInt, _tInt... _vSeq1, _tInt... _vSeq2>
118 struct vec_subtract<integer_sequence<_tInt, _vSeq1...>,
119 integer_sequence<_tInt, _vSeq2...>>
120 {
121 using type = integer_sequence<_tInt, (_vSeq1 - _vSeq2)...>;
122 };
123
124
130 template<typename _tInt, template<_tInt...> class _gOp, _tInt... _vSeq>
131 struct vdefer_i
132 : vseq::defer_i<_tInt, _gOp, integer_sequence<_tInt, _vSeq...>>
133 {};
134
135 } // namespace vseq;
137
139 using vseq::vdefer_i;
140
146
148 template<typename _tInt, _tInt, class>
149 struct make_successor;
150
151 template<typename _tInt, _tInt _vBase, class _tSeq>
152 using make_successor_t = _t<make_successor<_tInt, _vBase, _tSeq>>;
153
154 template<typename _tInt, _tInt _vBase, _tInt... _vSeq>
155 struct make_successor<_tInt, _vBase, integer_sequence<_tInt, _vSeq...>>
156 {
157 private:
158 using common_t = common_type_t<size_t, _tInt>;
159
160 public:
161 // XXX: Conversion to '_tInt' might be implementation-defined.
162 using type
163 = integer_sequence<_tInt, _vSeq..., static_cast<_tInt>(static_cast<
164 common_t>(_vBase) + static_cast<common_t>(sizeof...(_vSeq)))>;
165 };
167
168
170
171 template<typename _tInt, _tInt, size_t>
172 struct make_peano_sequence;
173
175 template<typename _tInt, _tInt _vBase, size_t _vN>
176 using make_peano_sequence_t
177 = _t<make_peano_sequence<_tInt, _vBase, _vN>>;
178
179 template<typename _tInt, _tInt _vBase, size_t _vN>
180 struct make_peano_sequence
181 {
182 using type = make_successor_t<_tInt, _vBase,
183 make_peano_sequence_t<_tInt, _vBase, _vN - 1>>;
184 };
185
186 template<typename _tInt, _tInt _vBase>
187 struct make_peano_sequence<_tInt, _vBase, 0>
188 {
189 using type = integer_sequence<_tInt>;
190 };
192
193
195
196 template<typename _tInt, size_t _vN>
197 using make_natural_sequence = make_peano_sequence<_tInt, 0, _vN>;
198
199 template<typename _tInt, size_t _vN>
200 using make_natural_sequence_t
201 = _t<make_natural_sequence<_tInt, _vN>>;
203
208 template<typename _tInt, _tInt _vDefault, _tInt... _values>
209 using same_value_as = is_same<integer_sequence<_tInt, _vDefault,
210 _values...>, integer_sequence<_tInt, _values..., _vDefault>>;
212
213
214 inline namespace cpp2014
215 {
216
223 #if __cpp_lib_integer_sequence >= 201304 || __cplusplus > 201103L
224 using std::make_integer_sequence;
225 using std::make_index_sequence;
226
227 using std::index_sequence_for;
228 #else
229 template<typename _tInt, size_t _vN>
230 using make_integer_sequence = make_natural_sequence_t<_tInt, _vN>;
231
232 template<size_t _vN>
233 using make_index_sequence = make_integer_sequence<size_t, _vN>;
234
235
236 template<typename... _types>
237 using index_sequence_for = make_index_sequence<sizeof...(_types)>;
238 #endif
239
240
241 } // inline namespace cpp2014;
242
243 } // namespace ystdex;
244
245 #endif
246
ystdex::vseq::enable_for_instances
enable_when< and_< is_instance< _tSeqs >..., same_instance< _tSeqs... >>::value > enable_for_instances
Definition: variadic.hpp:276
ystdex::vseq::vec_add
序列作为向量的加法。
Definition: variadic.hpp:817
ystdex::vseq::vec_subtract
序列作为向量的减法。
Definition: variadic.hpp:821
ystdex::identity
恒等元函数。
Definition: type_traits.hpp:961
platform::size_t
YF_API size_t
Definition: FileIO.h:1262
ystdex::cpp2014::integer_sequence::size
static size_t size() ynoexcept
Definition: integer_sequence.hpp:56
ystdex::make_peano_sequence_t
_t< make_peano_sequence< _tInt, _vBase, _vN >> make_peano_sequence_t
Definition: integer_sequence.hpp:177
ystdex::make_peano_sequence::type
make_successor_t< _tInt, _vBase, make_peano_sequence_t< _tInt, _vBase, _vN-1 >> type
Definition: integer_sequence.hpp:183
ystdex::vseq::project< _tSeq, index_sequence< _vIdxSeq... >, enable_for_instances< _tSeq > >::type
instance_apply_t< _tSeq, empty_base< at_t< params_of_t< _tSeq >, _vIdxSeq >... >> type
Definition: integer_sequence.hpp:81
ystdex::cpp2014::index_sequence
integer_sequence< size_t, _vSeq... > index_sequence
Definition: integer_sequence.hpp:63
ystdex::make_natural_sequence_t
_t< make_natural_sequence< _tInt, _vN >> make_natural_sequence_t
Definition: integer_sequence.hpp:201
ystdex::make_peano_sequence< _tInt, _vBase, 0 >::type
integer_sequence< _tInt > type
Definition: integer_sequence.hpp:189
ystdex::_t
typename _type::type _t
嵌套类型别名。
Definition: type_traits.hpp:96
ystdex::cpp2014::integer_sequence::value_type
_tInt value_type
Definition: integer_sequence.hpp:53
ystdex::make_successor_t
_t< make_successor< _tInt, _vBase, _tSeq >> make_successor_t
Definition: integer_sequence.hpp:152
vseq
ystdex::vseq::project
投影操作。
Definition: variadic.hpp:692
ystdex::make_successor< _tInt, _vBase, integer_sequence< _tInt, _vSeq... > >::type
integer_sequence< _tInt, _vSeq..., static_cast< _tInt >(static_cast< common_t >(_vBase)+static_cast< common_t >(sizeof...(_vSeq)))> type
Definition: integer_sequence.hpp:164
ystdex
特性测试宏。
Definition: ydef.h:796
ystdex::vseq::ctor_of
取类型构造器：具有 apply 成员，结果的嵌套 type 类型为构造类型的元函数。
Definition: variadic.hpp:214
ystdex::cpp2014::make_integer_sequence
make_natural_sequence_t< _tInt, _vN > make_integer_sequence
Definition: integer_sequence.hpp:230
variadic.hpp
C++ 变长参数相关操作。
ystdex::make_peano_sequence
取皮亚诺公理决定的整数序列。
Definition: integer_sequence.hpp:172
ystdex::vseq::defer_i
Definition: variadic.hpp:110
ystdex::empty_base
空基类模板。
Definition: ydef.h:902
ystdex::cpp2014::integer_sequence
Definition: integer_sequence.hpp:51
ystdex::vseq::vec_subtract< integer_sequence< _tInt, _vSeq1... >, integer_sequence< _tInt, _vSeq2... > >::type
integer_sequence< _tInt,(_vSeq1-_vSeq2)... > type
Definition: integer_sequence.hpp:121
ynoexcept
#define ynoexcept(...)
YSLib 无异常抛出保证：指定特定的异常规范。
Definition: ydef.h:720
ystdex::vseq::vdefer_i
可变参数整数列表延迟求值。
Definition: integer_sequence.hpp:131
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:654
ystdex::vseq::params_of
取类型构造器参数。
Definition: variadic.hpp:231
ystdex::vseq::instance_apply_t
defer_apply_t< ctor_of_t< _tSeq >, _tParamsList > instance_apply_t
使用构造器应用指定列表参数。
Definition: variadic.hpp:244
ystdex::cpp2014::make_index_sequence
make_integer_sequence< size_t, _vN > make_index_sequence
Definition: integer_sequence.hpp:233
ystdex::vseq::vec_add< integer_sequence< _tInt, _vSeq1... >, integer_sequence< _tInt, _vSeq2... > >::type
integer_sequence< _tInt,(_vSeq1+_vSeq2)... > type
Definition: integer_sequence.hpp:113
ystdex::same_value_as
is_same< integer_sequence< _tInt, _vDefault, _values... >, integer_sequence< _tInt, _values..., _vDefault >> same_value_as
判断是否具有相同的指定值。
Definition: integer_sequence.hpp:210
ystdex::cpp2014::index_sequence_for
make_index_sequence< sizeof...(_types)> index_sequence_for
Definition: integer_sequence.hpp:237
ystdex::make_successor< _tInt, _vBase, integer_sequence< _tInt, _vSeq... > >::common_t
common_type_t< size_t, _tInt > common_t
Definition: integer_sequence.hpp:158
ystdex::vseq::bound_integer_sequence
Definition: integer_sequence.hpp:87
ystdex::make_successor
取整数序列的自然数后继。
Definition: integer_sequence.hpp:149