YSTest: range.hpp 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

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

- 文件列表
- 文件成员

range.hpp
浏览该文件的文档.
1 /*
2 © 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_range_hpp_
29 #define YB_INC_ystdex_range_hpp_ 1
30
31 #include "../ydef.h"
32 #include <iterator> // for std::begin, std::end;
33
34 namespace ystdex
35 {
36
38
39 inline namespace cpp2011
40 {
41
42 using std::begin;
44 template<typename _type, size_t _vN>
45 yconstfn _type*
46 begin(_type(&&array)[_vN]) ynothrow
47 {
48 return array;
49 }
50 using std::end;
52 template<typename _type, size_t _vN>
53 yconstfn _type*
54 end(_type(&&array)[_vN]) ynothrow
55 {
56 return array + _vN;
57 }
58
59 } // inline namespace cpp2011;
60
61 inline namespace cpp2014
62 {
63
64 #if (__cplusplus >= 201402L && (!defined(__GLIBCXX__) \
65 || __GLIBCXX__ >= 20150119)) || (_LIBCXX_VERSION >= 1101 \
66 && _LIBCPP_STD_VER > 11) || YB_IMPL_MSCPP >= 1800
67 using std::cbegin;
68 using std::cend;
69 using std::rbegin;
70 using std::rend;
71 using std::crbegin;
72 using std::crend;
73 #else
74 // TODO: 'constexpr' on 'std::begin' and 'std::end' for array types since
75 // C++14?
76
77 template<typename _tRange>
78 yconstfn auto
79 cbegin(const _tRange& c) ynoexcept_spec(std::begin(c))
80 -> decltype(std::begin(c))
81 {
82 return std::begin(c);
83 }
84
85 template<typename _tRange>
86 yconstfn auto
87 cend(const _tRange& c) ynoexcept_spec(std::end(c)) -> decltype(std::end(c))
88 {
89 return std::end(c);
90 }
91
92 template<class _tRange>
93 auto
94 rbegin(_tRange& c) -> decltype(c.rbegin())
95 {
96 return c.rbegin();
97 }
98 template<class _tRange>
99 auto
100 rbegin(const _tRange& c) -> decltype(c.rbegin())
101 {
102 return c.rbegin();
103 }
104 template<typename _type, size_t _vN>
105 std::reverse_iterator<_type*>
106 rbegin(_type(&array)[_vN])
107 {
108 return std::reverse_iterator<_type*>(array + _vN);
109 }
110
111 template<typename _tElem>
112 std::reverse_iterator<const _tElem*>
113 rbegin(std::initializer_list<_tElem> il)
114 {
115 return std::reverse_iterator<const _tElem*>(il.end());
116 }
117
118 template<class _tRange>
119 auto rend(_tRange& c) -> decltype(c.rend())
120 {
121 return c.rend();
122 }
123 template<class _tRange>
124 auto rend(const _tRange& c) -> decltype(c.rend())
125 {
126 return c.rend();
127 }
128 template<typename _type, size_t _vN>
129 std::reverse_iterator<_type*>
130 rend(_type(&array)[_vN])
131 {
132 return std::reverse_iterator<_type*>(array);
133 }
134 template<typename _tElem>
135 std::reverse_iterator<const _tElem*>
136 rend(std::initializer_list<_tElem> il)
137 {
138 return std::reverse_iterator<const _tElem*>(il.begin());
139 }
140
141 template<typename _tRange>
142 auto
143 crbegin(const _tRange& c) -> decltype(ystdex::rbegin(c))
144 {
145 return ystdex::rbegin(c);
146 }
147
148 template<typename _tRange>
149 auto
150 crend(const _tRange& c) -> decltype(ystdex::rend(c))
151 {
152 return ystdex::rend(c);
153 }
154 #endif
155
157
158 template<typename _type, size_t _vN>
159 yconstfn _type*
160 cbegin(_type(&&array)[_vN]) ynothrow
161 {
162 return array;
163 }
164
165 template<typename _type, size_t _vN>
166 yconstfn _type*
167 cend(_type(&&array)[_vN]) ynothrow
168 {
169 return array + _vN;
170 }
171
172 template<typename _type, size_t _vN>
173 std::reverse_iterator<_type*>
174 rbegin(_type(&&array)[_vN])
175 {
176 return std::reverse_iterator<_type*>(array + _vN);
177 }
178
179 template<typename _type, size_t _vN>
180 std::reverse_iterator<_type*>
181 rend(_type(&&array)[_vN])
182 {
183 return std::reverse_iterator<_type*>(array);
184 }
185
186 #if __cplusplus <= 201402L
187
189 template<typename _tElem>
190 yconstfn const _tElem*
191 cbegin(std::initializer_list<_tElem> il) ynothrow
192 {
193 return il.begin();
194 }
195
197 template<typename _tElem>
198 yconstfn const _tElem*
199 cend(std::initializer_list<_tElem> il) ynothrow
200 {
201 return il.end();
202 }
203
204 template<typename _tElem>
205 yconstfn std::reverse_iterator<const _tElem*>
206 crbegin(std::initializer_list<_tElem> il) ynothrow
207 {
208 return ystdex::rbegin(il);
209 }
210
211 template<typename _tElem>
212 yconstfn std::reverse_iterator<const _tElem*>
213 crend(std::initializer_list<_tElem> il) ynothrow
214 {
215 return ystdex::rend(il);
216 }
218 #endif
219
220
221 } // inline namespace cpp2014;
223
231 template<class _tRange>
232 yconstfn auto
233 size(const _tRange& c) -> decltype(c.size())
234 {
235 return c.size();
236 }
237 template<typename _type, size_t _vN>
238 yconstfn size_t
239 size(const _type(&)[_vN]) ynothrow
240 {
241 return _vN;
242 }
243 #if __cplusplus <= 201402L
244 template<typename _tElem>
246 yconstfn size_t
247 size(std::initializer_list<_tElem> il) ynothrow
248 {
249 return il.size();
250 }
251 #endif
252
253 template<class _tRange>
254 yconstfn auto
255 empty(const _tRange& c) -> decltype(c.empty())
256 {
257 return c.empty();
258 }
259 template<typename _type, size_t _vN>
260 yconstfn bool
261 empty(const _type(&)[_vN]) ynothrow
262 {
263 return {};
264 }
265 template<typename _type, size_t _vN>
266 yconstfn bool
267 empty(const _type(&&)[_vN]) ynothrow
268 {
269 return {};
270 }
271 template<typename _tElem>
272 yconstfn bool
273 empty(std::initializer_list<_tElem> il) ynothrow
274 {
275 return il.size() == 0;
276 }
277
278 template<typename _tRange>
279 yconstfn auto
280 data(_tRange& c) -> decltype(c.data())
281 {
282 return c.data();
283 }
284 template<typename _tRange>
285 yconstfn auto
286 data(const _tRange& c) -> decltype(c.data())
287 {
288 return c.data();
289 }
290 template<typename _type, size_t _vN>
291 yconstfn _type*
292 data(_type(&array)[_vN]) ynothrow
293 {
294 return array;
295 }
296 template<typename _type, size_t _vN>
297 yconstfn _type*
298 data(_type(&&array)[_vN]) ynothrow
299 {
300 return array;
301 }
302 template<typename _tElem>
303 yconstfn const _tElem*
304 data(std::initializer_list<_tElem> il) ynothrow
305 {
306 return il.begin();
307 }
309
310 } // namespace ystdex;
311
312 #endif
313
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:680
ystdex::cpp2014::cend
const _tElem * cend(std::initializer_list< _tElem > il)
Definition: range.hpp:199
ystdex::cpp2014::rbegin
auto rbegin(_tRange &c) -> decltype(c.rbegin())
Definition: range.hpp:94
ynoexcept_spec
#define ynoexcept_spec(...)
表达式 noexcept 异常规范。
Definition: ydef.h:794
ystdex::cpp2014::crend
auto crend(const _tRange &c) -> decltype(ystdex::rend(c))
Definition: range.hpp:150
ystdex::empty
auto empty(const _tRange &c) -> decltype(c.empty())
Definition: range.hpp:255
ystdex::cpp2014::crend
std::reverse_iterator< const _tElem * > crend(std::initializer_list< _tElem > il)
Definition: range.hpp:213
ystdex::cpp2014::cend
auto cend(const _tRange &c) -> decltype(std::end(c))
Definition: range.hpp:87
ystdex::cpp2014::cbegin
const _tElem * cbegin(std::initializer_list< _tElem > il)
Definition: range.hpp:191
ystdex::data
auto data(_tRange &c) -> decltype(c.data())
Definition: range.hpp:280
ystdex::cpp2011::end
_type * end(_type(&&array)[_vN])
Definition: range.hpp:54
ystdex::cpp2014::rend
auto rend(_tRange &c) -> decltype(c.rend())
Definition: range.hpp:119
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:766
ystdex::cpp2014::cbegin
auto cbegin(const _tRange &c) -> decltype(std::begin(c))
Definition: range.hpp:79
ystdex
特性测试宏。
Definition: ydef.h:822
ystdex::cpp2014::crbegin
std::reverse_iterator< const _tElem * > crbegin(std::initializer_list< _tElem > il)
Definition: range.hpp:206
ystdex::cpp2014::crbegin
auto crbegin(const _tRange &c) -> decltype(ystdex::rbegin(c))
Definition: range.hpp:143
CHRLib::c
c
Definition: CharacterProcessing.h:81
ystdex::cpp2014::rend
std::reverse_iterator< _type * > rend(_type(&&array)[_vN])
Definition: range.hpp:181
ystdex::cpp2011::begin
_type * begin(_type(&&array)[_vN])
Definition: range.hpp:46
ystdex::size
auto size(const _tRange &c) -> decltype(c.size())
类容器访问。
Definition: range.hpp:233
ystdex::cpp2014::rbegin
std::reverse_iterator< _type * > rbegin(_type(&&array)[_vN])
Definition: range.hpp:174