YSTest: iterator_op.hpp 源文件

YSTest PreAlpha_b700_20160611 The YSLib Test Project

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

- 文件列表
- 文件成员

iterator_op.hpp
浏览该文件的文档.
1 /*
2 © 2013-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_iterator_op_hpp_
29 #define YB_INC_ystdex_iterator_op_hpp_ 1
30
31 #include "range.hpp" // for std::next, std::prev, std::make_move_iterator,
32 // std::reverse_iterator, std::make_pair, begin, end;
33 #include "cassert.h" // for yconstraint;
34 #include "deref_op.hpp" // for is_undereferenceable;
35 #include "operators.hpp" // for input_iteratable, output_iteratable,
36 // forward_iteratable, bidirectional_iteratable, random_access_iteratable, _t;
37
38 namespace ystdex
39 {
40
53 template<typename _tIn, typename _fPred>
54 _tIn
55 next_if(_tIn i, _fPred f,
56 typename std::iterator_traits<_tIn>::difference_type n = 1)
57 {
58 yconstraint(!is_undereferenceable(i));
59 return f(*i) ? std::next(i, n) : i;
60 }
61 template<typename _tIn, typename _type>
62 _tIn
63 next_if_eq(_tIn i, const _type& val,
64 typename std::iterator_traits<_tIn>::difference_type n = 1)
65 {
66 yconstraint(!is_undereferenceable(i));
67 return *i == val ? std::next(i, n) : i;
68 }
70
76 template<typename _tBi, typename _fPred>
77 _tBi
78 prev_if(_tBi i, _fPred f,
79 typename std::iterator_traits<_tBi>::difference_type n = 1)
80 {
81 return f(*i) ? std::prev(i, n) : i;
82 }
83 template<typename _tBi, typename _type>
84 _tBi
85 prev_if_eq(_tBi i, const _type& val,
86 typename std::iterator_traits<_tBi>::difference_type n = 1)
87 {
88 return *i == val ? std::prev(i, n) : i;
89 }
91
92
93
95
96
102 #if __cpp_lib_make_reverse_iterator >= 201402 || __cplusplus >= 201402L
103 using std::make_reverse_iterator;
104 #else
105 template<typename _tIter>
106 std::reverse_iterator<_tIter>
107 make_reverse_iterator(_tIter i)
108 {
109 return std::reverse_iterator<_tIter>(i);
110 }
111 #endif
112
117 template<typename _tIter1, typename _tIter2>
118 inline auto
119 make_move_iterator_pair(_tIter1 it1, _tIter2 it2) -> decltype(
120 std::make_pair(std::make_move_iterator(it1), std::make_move_iterator(it2)))
121 {
122 return std::make_pair(std::make_move_iterator(it1),
123 std::make_move_iterator(it2));
124 }
131 template<typename _tRange>
132 inline auto
133 make_move_iterator_pair(_tRange& c)
134 -> decltype(ystdex::make_move_iterator_pair(c.begin(), c.end()))
135 {
136 return ystdex::make_move_iterator_pair(begin(c), end(c));
137 }
139
140
142 namespace details
143 {
144
145 template<typename _tIter, typename _tTraits,
146 typename _tTag = typename _tTraits::iterator_category>
147 struct iterator_operators;
148
149 template<typename _tIter, typename _tTraits>
150 struct iterator_operators<_tIter, _tTraits, std::input_iterator_tag>
151 {
152 using type = input_iteratable<_tIter, typename _tTraits::reference>;
153 };
154
155 template<typename _tIter, typename _tTraits>
156 struct iterator_operators<_tIter, _tTraits, std::output_iterator_tag>
157 {
158 using type = output_iteratable<_tIter, typename _tTraits::reference>;
159 };
160
161 template<typename _tIter, typename _tTraits>
162 struct iterator_operators<_tIter, _tTraits, std::forward_iterator_tag>
163 {
164 using type = forward_iteratable<_tIter, typename _tTraits::reference>;
165 };
166
167 template<typename _tIter, typename _tTraits>
168 struct iterator_operators<_tIter, _tTraits, std::bidirectional_iterator_tag>
169 {
170 using type = bidirectional_iteratable<_tIter, typename _tTraits::reference>;
171 };
172
173 template<typename _tIter, typename _tTraits>
174 struct iterator_operators<_tIter, _tTraits, std::random_access_iterator_tag>
175 {
176 using type = random_access_iteratable<_tIter,
177 typename _tTraits::difference_type, typename _tTraits::reference>;
178 };
179
180 } // namespace details;
181
182
190 template<typename _tIter, typename _tTraits = std::iterator_traits<_tIter>>
191 using iterator_operators_t = _t<details::iterator_operators<_tIter, _tTraits>>;
192
193 } // namespace ystdex;
194
195 #endif
196
ystdex::prev_if_eq
_tBi prev_if_eq(_tBi i, const _type &val, typename std::iterator_traits< _tBi >::difference_type n=1)
Definition: iterator_op.hpp:85
ystdex::make_reverse_iterator
std::reverse_iterator< _tIter > make_reverse_iterator(_tIter i)
构造反向迭代器。
Definition: iterator_op.hpp:107
yconstraint
#define yconstraint(_expr)
约束：接口语义。
Definition: cassert.h:82
cassert.h
ISO C 断言/调试跟踪扩展。
deref_op.hpp
解引用操作。
ystdex::details::ebases
Definition: operators.hpp:100
range.hpp
范围操作。
ystdex::next_if
_tIn next_if(_tIn i, _fPred f, typename std::iterator_traits< _tIn >::difference_type n=1)
迭代器指向的值满足条件时取邻接迭代器，否则取原值。
Definition: iterator_op.hpp:55
CHRLib::c
c
Definition: CharacterProcessing.h:81
ystdex::make_move_iterator_pair
auto make_move_iterator_pair(_tIter1 it1, _tIter2 it2) -> decltype(std::make_pair(std::make_move_iterator(it1), std::make_move_iterator(it2)))
构造转移迭代器对。
Definition: iterator_op.hpp:119
std
Definition: memory.hpp:1100
ystdex::_t
typename _type::type _t
嵌套类型别名。
Definition: type_traits.hpp:96
ystdex::iterator_operators_t
_t< details::iterator_operators< _tIter, _tTraits >> iterator_operators_t
按迭代器类别取可实现迭代器的重载操作符集合的实现。
Definition: iterator_op.hpp:191
ystdex
特性测试宏。
Definition: ydef.h:796
ystdex::is_undereferenceable
bool is_undereferenceable(const _tIter &)
Definition: deref_op.hpp:45
ystdex::next_if_eq
_tIn next_if_eq(_tIn i, const _type &val, typename std::iterator_traits< _tIn >::difference_type n=1)
Definition: iterator_op.hpp:63
YSLib::i
return i
Definition: YCoreUtilities.h:176
operators.hpp
重载操作符。
ystdex::prev_if
_tBi prev_if(_tBi i, _fPred f, typename std::iterator_traits< _tBi >::difference_type n=1)
迭代器指向的值满足条件时取反向邻接迭代器，否则取原值。
Definition: iterator_op.hpp:78
ystdex::cpp2011::begin
_type * begin(_type(&&array)[_vN])
Definition: range.hpp:46
YSLib::IO::f
const string &path const String &path _func f
Definition: YSLib/Service/FileSystem.h:430
ystdex::details::iterator_operators
Definition: iterator_op.hpp:147
ystdex::cpp2011::end
_type * end(_type(&&array)[_vN])
Definition: range.hpp:54
platform::n
size_t n
Definition: YCLib/FileSystem.cpp:321