YSTest: integer_sequence.hpp 源文件

YSTest PreAlpha_b800_20170810 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 fseq
73 {
74
80 template<typename _tInt, _tInt _vInt, _tInt... _vSeq>
81 yconstfn std::integral_constant<_tInt, _vInt>
82 front(integer_sequence<_tInt, _vInt, _vSeq...>) ynothrow
83 {
84 return {};
85 }
86
87 template<typename _tInt, _tInt _vInt, _tInt... _vSeq>
88 yconstfn integer_sequence<_tInt, _vSeq...>
89 pop_front(integer_sequence<_tInt, _vInt, _vSeq...>) ynothrow
90 {
91 return {};
92 }
93
94 template<typename _func, typename _tState, typename _tInt>
95 yconstfn _tState
96 fold(_func, _tState s, integer_sequence<_tInt>) ynothrow
97 {
98 return s;
99 }
100 template<typename _func, typename _tState, typename _tInt, _tInt _vInt,
101 _tInt... _vSeq>
102 yconstfn auto
103 fold(_func f, _tState s, integer_sequence<_tInt, _vInt, _vSeq...> xs) ynothrow
104 -> decltype(fold(f, f(s, front(xs)), pop_front(xs)))
105 {
106 return fold(f, f(s, front(xs)), pop_front(xs));
107 }
108
109
110 struct plus
111 {
113 template<typename _tInt, _tInt _v1, _tInt _v2>
114 yconstfn auto
115 operator()(std::integral_constant<_tInt, _v1>, std::integral_constant<_tInt,
116 _v2>) const ynothrow -> std::integral_constant<_tInt, _v1 + _v2>
117 {
118 return {};
119 }
120 };
121
122
123 struct minus
124 {
126 template<typename _tInt, _tInt _v1, _tInt _v2>
127 yconstfn auto
128 operator()(std::integral_constant<_tInt, _v1>, std::integral_constant<_tInt,
129 _v2>) const ynothrow -> std::integral_constant<_tInt, _v1 - _v2>
130 {
131 return {};
132 }
133 };
135
136 } // namespace fseq;
138
140
141 namespace vseq
142 {
143
145
146 template<class _tSeq, size_t... _vIdxSeq>
147 struct project<_tSeq, index_sequence<_vIdxSeq...>, enable_for_instances<_tSeq>>
148 {
149 using type = instance_apply_t<_tSeq,
150 empty_base<at_t<params_of_t<_tSeq>, _vIdxSeq>...>>;
151 };
152
153
155 template<typename _tInt>
156 struct bound_integer_sequence
157 {
158 template<typename... _types>
159 using apply = identity<integer_sequence<_tInt, _types::value...>>;
160 };
161
162
163 template<typename _tInt, _tInt... _vSeq>
164 struct ctor_of<integer_sequence<_tInt, _vSeq...>>
165 {
166 using type = bound_integer_sequence<_tInt>;
167 };
168
169
170 template<typename _tInt, _tInt... _vSeq>
171 struct params_of<integer_sequence<_tInt, _vSeq...>>
172 {
173 using type = empty_base<integral_constant<_tInt, _vSeq>...>;
174 };
176
177
178 template<typename _tInt, _tInt... _vSeq1, _tInt... _vSeq2>
179 struct vec_add<integer_sequence<_tInt, _vSeq1...>,
180 integer_sequence<_tInt, _vSeq2...>>
181 {
182 using type = integer_sequence<_tInt, (_vSeq1 + _vSeq2)...>;
183 };
184
185
186 template<typename _tInt, _tInt... _vSeq1, _tInt... _vSeq2>
187 struct vec_subtract<integer_sequence<_tInt, _vSeq1...>,
188 integer_sequence<_tInt, _vSeq2...>>
189 {
190 using type = integer_sequence<_tInt, (_vSeq1 - _vSeq2)...>;
191 };
192
193
199 template<typename _tInt, template<_tInt...> class _gOp, _tInt... _vSeq>
200 struct vdefer_i
201 : vseq::defer_i<_tInt, _gOp, integer_sequence<_tInt, _vSeq...>>
202 {};
203
204 } // namespace vseq;
206
208 using vseq::vdefer_i;
209
215
217 template<typename _tInt, _tInt, class>
218 struct make_successor;
219
220 template<typename _tInt, _tInt _vBase, class _tSeq>
221 using make_successor_t = _t<make_successor<_tInt, _vBase, _tSeq>>;
222
223 template<typename _tInt, _tInt _vBase, _tInt... _vSeq>
224 struct make_successor<_tInt, _vBase, integer_sequence<_tInt, _vSeq...>>
225 {
226 private:
227 using common_t = common_type_t<size_t, _tInt>;
228
229 public:
230 // XXX: Conversion to '_tInt' might be implementation-defined.
231 using type
232 = integer_sequence<_tInt, _vSeq..., static_cast<_tInt>(static_cast<
233 common_t>(_vBase) + static_cast<common_t>(sizeof...(_vSeq)))>;
234 };
236
237
239
240 template<typename _tInt, _tInt, size_t>
241 struct make_peano_sequence;
242
244 template<typename _tInt, _tInt _vBase, size_t _vN>
245 using make_peano_sequence_t
246 = _t<make_peano_sequence<_tInt, _vBase, _vN>>;
247
248 template<typename _tInt, _tInt _vBase, size_t _vN>
249 struct make_peano_sequence
250 {
251 using type = make_successor_t<_tInt, _vBase,
252 make_peano_sequence_t<_tInt, _vBase, _vN - 1>>;
253 };
254
255 template<typename _tInt, _tInt _vBase>
256 struct make_peano_sequence<_tInt, _vBase, 0>
257 {
258 using type = integer_sequence<_tInt>;
259 };
261
262
264
265 template<typename _tInt, size_t _vN>
266 using make_natural_sequence = make_peano_sequence<_tInt, 0, _vN>;
267
268 template<typename _tInt, size_t _vN>
269 using make_natural_sequence_t
270 = _t<make_natural_sequence<_tInt, _vN>>;
272
277 template<typename _tInt, _tInt _vDefault, _tInt... _values>
278 using same_value_as = is_same<integer_sequence<_tInt, _vDefault,
279 _values...>, integer_sequence<_tInt, _values..., _vDefault>>;
281
282
283 inline namespace cpp2014
284 {
285
292 #if __cpp_lib_integer_sequence >= 201304 || __cplusplus > 201103L
293 using std::make_integer_sequence;
294 using std::make_index_sequence;
295
296 using std::index_sequence_for;
297 #else
298 template<typename _tInt, size_t _vN>
299 using make_integer_sequence = make_natural_sequence_t<_tInt, _vN>;
300
301 template<size_t _vN>
302 using make_index_sequence = make_integer_sequence<size_t, _vN>;
303
304
305 template<typename... _types>
306 using index_sequence_for = make_index_sequence<sizeof...(_types)>;
307 #endif
308
309
310 } // inline namespace cpp2014;
311
312 } // namespace ystdex;
313
314 #endif
315
ystdex::vseq::vdefer_i
可变参数整数列表延迟求值。
Definition: integer_sequence.hpp:200
ystdex::fseq::pop_front
empty_base< _types... > pop_front(empty_base< _type, _types... >)
Definition: variadic.hpp:81
ystdex::fseq::plus::operator()
auto operator()(std::integral_constant< _tInt, _v1 >, std::integral_constant< _tInt, _v2 >) const -> std::integral_constant< _tInt, _v1+_v2 >
Definition: integer_sequence.hpp:115
ystdex::vseq::vec_subtract< integer_sequence< _tInt, _vSeq1... >, integer_sequence< _tInt, _vSeq2... > >::type
integer_sequence< _tInt,(_vSeq1-_vSeq2)... > type
Definition: integer_sequence.hpp:190
ystdex::cpp2014::index_sequence_for
make_index_sequence< sizeof...(_types)> index_sequence_for
Definition: integer_sequence.hpp:306
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:680
ystdex::make_peano_sequence< _tInt, _vBase, 0 >::type
integer_sequence< _tInt > type
Definition: integer_sequence.hpp:258
ystdex::vseq::ctor_of
取类型构造器：具有 apply 成员，结果的嵌套 type 类型为构造类型的元函数。
Definition: variadic.hpp:279
ystdex::vseq::defer_i
Definition: variadic.hpp:175
ystdex::cpp2014::index_sequence
integer_sequence< size_t, _vSeq... > index_sequence
Definition: integer_sequence.hpp:63
platform::size_t
YF_API size_t
Definition: FileIO.h:1353
ystdex::identity
恒等元函数。
Definition: type_traits.hpp:999
variadic.hpp
C++ 变长参数相关操作。
CHRLib::f
f(d, s)
ystdex::fseq::minus::operator()
auto operator()(std::integral_constant< _tInt, _v1 >, std::integral_constant< _tInt, _v2 >) const -> std::integral_constant< _tInt, _v1-_v2 >
Definition: integer_sequence.hpp:128
ystdex::fseq::fold
_tState fold(_func, _tState s, integer_sequence< _tInt >)
Definition: integer_sequence.hpp:96
ystdex::fseq::plus
Definition: integer_sequence.hpp:110
ystdex::vseq::vec_add
序列作为向量的加法。
Definition: variadic.hpp:881
ystdex::cpp2014::integer_sequence::value_type
_tInt value_type
Definition: integer_sequence.hpp:53
ystdex::make_peano_sequence::type
make_successor_t< _tInt, _vBase, make_peano_sequence_t< _tInt, _vBase, _vN-1 >> type
Definition: integer_sequence.hpp:252
ystdex::make_successor_t
_t< make_successor< _tInt, _vBase, _tSeq >> make_successor_t
Definition: integer_sequence.hpp:221
ystdex::vseq::instance_apply_t
defer_apply_t< ctor_of_t< _tSeq >, _tParamsList > instance_apply_t
使用构造器应用指定列表参数。
Definition: variadic.hpp:309
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:766
ystdex::make_successor< _tInt, _vBase, integer_sequence< _tInt, _vSeq... > >::common_t
common_type_t< size_t, _tInt > common_t
Definition: integer_sequence.hpp:227
CHRLib::s
_tDst const _tSrc * s
Definition: CharacterProcessing.h:140
ystdex
特性测试宏。
Definition: ydef.h:822
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:233
ystdex::vseq::vec_subtract
序列作为向量的减法。
Definition: variadic.hpp:885
ystdex::same_value_as
is_same< integer_sequence< _tInt, _vDefault, _values... >, integer_sequence< _tInt, _values..., _vDefault >> same_value_as
判断是否具有相同的指定值。
Definition: integer_sequence.hpp:279
ystdex::vseq::vec_add< integer_sequence< _tInt, _vSeq1... >, integer_sequence< _tInt, _vSeq2... > >::type
integer_sequence< _tInt,(_vSeq1+_vSeq2)... > type
Definition: integer_sequence.hpp:182
ystdex::_t
typename _type::type _t
嵌套类型别名。
Definition: type_traits.hpp:97
ystdex::fseq::front
identity< _type > front(empty_base< _type, _types... >)
Definition: variadic.hpp:74
ystdex::vseq::enable_for_instances
enable_when< and_< is_instance< _tSeqs >..., same_instance< _tSeqs... >>::value > enable_for_instances
Definition: variadic.hpp:341
ystdex::make_peano_sequence
取皮亚诺公理决定的整数序列。
Definition: integer_sequence.hpp:241
ystdex::vseq::bound_integer_sequence
Definition: integer_sequence.hpp:156
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:150
ystdex::cpp2014::integer_sequence::size
static size_t size() ynoexcept
Definition: integer_sequence.hpp:56
std
Definition: memory.hpp:1183
ystdex::empty_base
空基类模板。
Definition: ydef.h:928
ystdex::fseq::minus
Definition: integer_sequence.hpp:123
ystdex::cpp2014::make_integer_sequence
make_natural_sequence_t< _tInt, _vN > make_integer_sequence
Definition: integer_sequence.hpp:299
ystdex::vseq::project
投影操作。
Definition: variadic.hpp:756
vseq
ystdex::vseq::params_of
取类型构造器参数。
Definition: variadic.hpp:296
ystdex::cpp2014::make_index_sequence
make_integer_sequence< size_t, _vN > make_index_sequence
Definition: integer_sequence.hpp:302
ystdex::make_peano_sequence_t
_t< make_peano_sequence< _tInt, _vBase, _vN >> make_peano_sequence_t
Definition: integer_sequence.hpp:246
ystdex::cpp2014::integer_sequence
Definition: integer_sequence.hpp:51
ystdex::make_natural_sequence_t
_t< make_natural_sequence< _tInt, _vN >> make_natural_sequence_t
Definition: integer_sequence.hpp:270
ystdex::make_successor
取整数序列的自然数后继。
Definition: integer_sequence.hpp:218
ynoexcept
#define ynoexcept(...)
YSLib 无异常抛出保证：指定特定的异常规范。
Definition: ydef.h:746