YSTest: variadic.hpp 源文件

YSTest PreAlpha_b500_20140530 The YSLib Test Project

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

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
variadic.hpp
浏览该文件的文档.
1 /*
2 © 2013 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_variadic_hpp_
29 #define YB_INC_ystdex_variadic_hpp_ 1
30
31 #include "../ydef.h" // for ystdex::size_t;
32
33 namespace ystdex
34 {
35
41 template<size_t... _vSeq>
42 struct variadic_sequence
43 {
49 static yconstfn size_t
50 size()
51 {
52 return sizeof...(_vSeq);
53 }
54 };
55
56
77 template<class>
78 struct sequence_split;
79
80 template<class _tSeq>
81 using sequence_split_t = typename sequence_split<_tSeq>::type;
82
83 template<size_t _vHead, size_t... _vTail>
84 struct sequence_split<variadic_sequence<_vHead, _vTail...>>
85 {
86 static yconstexpr size_t value = _vHead;
87
88 using type = variadic_sequence<value>;
89 using tail = variadic_sequence<_vTail...>;
90 };
92
93
100 template<class, class>
101 struct sequence_cat;
102
103 template<class _tSeq1, class _tSeq2>
104 using sequence_cat_t = typename sequence_cat<_tSeq1, _tSeq2>::type;
105
106 template<size_t... _vSeq1, size_t... _vSeq2>
107 struct sequence_cat<variadic_sequence<_vSeq1...>, variadic_sequence<_vSeq2...>>
108 {
109 using type = variadic_sequence<_vSeq1..., _vSeq2...>;
110 };
112
113
120 template<size_t, class>
121 struct sequence_element;
122
123 template<size_t _vIdx, class _tSeq>
124 using sequence_element_t = typename sequence_element<_vIdx, _tSeq>::type;
125
126 template<size_t _vIdx>
127 struct sequence_element<_vIdx, variadic_sequence<>>;
128
129 template<size_t... _vSeq>
130 struct sequence_element<0, variadic_sequence<_vSeq...>>
131 {
132 private:
133 using vseq = variadic_sequence<_vSeq...>;
134
135 public:
136 static yconstexpr auto value = sequence_split<vseq>::value;
137
138 using type = sequence_split_t<vseq>;
139 };
140
141 template<size_t _vIdx, size_t... _vSeq>
142 struct sequence_element<_vIdx, variadic_sequence<_vSeq...>>
143 {
144 private:
145 using sub = sequence_element<_vIdx - 1,
146 typename sequence_split<variadic_sequence<_vSeq...>>::tail>;
147
148 public:
149 static yconstexpr auto value = sub::value;
150 using type = typename sub::type;
151 };
153
154
161 template<class, class>
162 struct sequence_project;
163
164 template<class _tSeq, class _tIdxSeq>
165 using sequence_project_t = typename sequence_project<_tSeq, _tIdxSeq>::type;
166
167 template<size_t... _vSeq, size_t... _vIdxSeq>
168 struct sequence_project<variadic_sequence<_vSeq...>,
169 variadic_sequence<_vIdxSeq...>>
170 {
171 using type = variadic_sequence<
172 sequence_element<_vIdxSeq, variadic_sequence<_vSeq...>>::value...>;
173 };
175
176
183 template<class>
184 struct sequence_reverse;
185
186 template<class _tSeq>
187 using sequence_reverse_t = typename sequence_reverse<_tSeq>::type;
188
189 template<>
190 struct sequence_reverse<variadic_sequence<>>
191 {
192 using type = variadic_sequence<>;
193 };
194
195 template<size_t... _vSeq>
196 struct sequence_reverse<variadic_sequence<_vSeq...>>
197 {
198 private:
199 using vseq = variadic_sequence<_vSeq...>;
200
201 public:
202 using type = sequence_cat_t<sequence_reverse_t<typename
203 sequence_split<vseq>::tail>, sequence_split_t<vseq>>;
204 };
206
207
214 template<class>
215 struct make_successor;
216
218 template<class _tSeq>
219 using make_successor_t = typename make_successor<_tSeq>::type;
220
221 template<size_t... _vSeq>
222 struct make_successor<variadic_sequence<_vSeq...>>
223 {
224 using type = variadic_sequence<_vSeq..., sizeof...(_vSeq)>;
225 };
227
228
235 template<size_t>
236 struct make_natural_sequence;
237
239 template<size_t _vN>
240 using make_natural_sequence_t = typename make_natural_sequence<_vN>::type;
241
242 template<size_t _vN>
243 struct make_natural_sequence
244 {
245 using type = make_successor_t<make_natural_sequence_t<_vN - 1>>;
246 };
247
248 template<>
249 struct make_natural_sequence<0>
250 {
251 using type = variadic_sequence<>;
252 };
254
255 } // namespace ystdex;
256
257 #endif
258
ystdex::sequence_project_t
typename sequence_project< _tSeq, _tIdxSeq >::type sequence_project_t
Definition: variadic.hpp:165
ystdex::sequence_element< 0, variadic_sequence< _vSeq...> >::type
sequence_split_t< vseq > type
Definition: variadic.hpp:138
ystdex::make_natural_sequence
取自然数变量标记序列。
Definition: variadic.hpp:236
ystdex::sequence_element
取序列元素。
Definition: variadic.hpp:121
ystdex::sequence_reverse_t
typename sequence_reverse< _tSeq >::type sequence_reverse_t
Definition: variadic.hpp:187
ystdex::variadic_sequence
变长参数标记的整数序列。
Definition: variadic.hpp:42
ystdex::make_natural_sequence::type
make_successor_t< make_natural_sequence_t< _vN-1 >> type
Definition: variadic.hpp:245
ystdex::sequence_split_t
typename sequence_split< _tSeq >::type sequence_split_t
Definition: variadic.hpp:81
ystdex::make_successor_t
typename make_successor< _tSeq >::type make_successor_t
Definition: variadic.hpp:219
ystdex::sequence_element< _vIdx, variadic_sequence< _vSeq...> >::type
typename sub::type type
Definition: variadic.hpp:150
ystdex::sequence_cat_t
typename sequence_cat< _tSeq1, _tSeq2 >::type sequence_cat_t
Definition: variadic.hpp:104
ystdex::sequence_cat
合并序列。
Definition: variadic.hpp:101
ystdex::sequence_split
拆分序列。
Definition: variadic.hpp:78
ystdex::variadic_sequence::size
static size_t size()
取序列长度。
Definition: variadic.hpp:50
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:463
ystdex::sequence_element_t
typename sequence_element< _vIdx, _tSeq >::type sequence_element_t
Definition: variadic.hpp:124
ystdex::sequence_project
投影操作。
Definition: variadic.hpp:162
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:462
ystdex::make_successor
取整数序列的自然数后继。
Definition: variadic.hpp:215
ystdex::sequence_reverse< variadic_sequence< _vSeq...> >::type
sequence_cat_t< sequence_reverse_t< typename sequence_split< vseq >::tail >, sequence_split_t< vseq >> type
Definition: variadic.hpp:203
ystdex::sequence_reverse
取逆序列。
Definition: variadic.hpp:184
ystdex::make_natural_sequence_t
typename make_natural_sequence< _vN >::type make_natural_sequence_t
Definition: variadic.hpp:240