28 #ifndef _H_GRB_ITERATOR_ADAPTER 29 #define _H_GRB_ITERATOR_ADAPTER 38 namespace grb::utils {
63 typename std::enable_if< std::is_same<
64 typename std::iterator_traits< SubIterT >::iterator_category,
65 std::random_access_iterator_tag
66 >::value,
void >::type * =
nullptr 74 typedef typename SubIterT::iterator_category iterator_category;
76 typedef typename SubIterT::difference_type difference_type;
78 typedef typename SubIterT::value_type value_type;
80 typedef typename SubIterT::pointer pointer;
95 typedef const value_type & const_reference;
97 typedef const value_type * const_pointer;
108 std::function< value_type(
const value_type) > adapter_func;
116 const SubIterT iter_in,
const SubIterT iter_end,
117 const std::function< value_type(
const value_type ) > func_in
118 ) : iter( iter_in ), end_it( iter_end ), adapter_func( func_in ) {
119 if( iter != end_it ) {
120 v = adapter_func( *iter );
126 iter( other.iter ), end_it( other.end_it ),
127 adapter_func( other.adapter_func )
131 v( std::move( other.v ) ),
132 iter( std::move( other.iter ) ), end_it( std::move( other.end_it ) ),
133 adapter_func( std::move( other.adapter_func ) )
142 const_reference operator*()
const noexcept {
149 end_it = other.end_it;
150 adapter_func = other.adapter_func;
157 v = std::move( other.v );
158 iter = std::move( other.iter );
159 end_it = std::move( other.end_it );
160 adapter_func = std::move( other.adapter_func );
166 if( iter != end_it ) {
167 v = adapter_func( *iter );
173 std::swap( left.v, right.v );
174 std::swap( left.iter, right.iter );
175 std::swap( left.end_it, right.end_it );
176 std::swap( left.adapter_func, right.adapter_func );
181 const_pointer operator->()
const noexcept {
188 if( iter != end_it ) {
189 v = adapter_func( *iter );
194 friend bool operator==(
197 return left.iter == right.iter;
200 friend bool operator!=(
203 return !(left == right);
210 if( iter != end_it ) {
211 v = adapter_func( *iter );
219 if( iter != end_it ) {
220 v = adapter_func( *iter );
232 value_type operator[](
const size_t i )
const noexcept {
233 return adapter_func( iter[ i ] );
236 friend bool operator<(
240 return left.iter < right.iter;
243 friend bool operator>(
247 return left.iter > right.iter;
250 friend bool operator<=(
254 return left.iter <= right.iter;
257 friend bool operator>=(
261 return left.iter >= right.iter;
266 if( iter != end_it ) {
267 v = adapter_func( *iter );
276 const SubIterT subRet = iterator.iter + count;
277 return self_type( subRet, iterator.end_it, iterator.adapter_func );
284 const SubIterT subRet = iterator.iter + count;
285 return self_type( subRet, iterator.end_it, iterator.adapter_func );
290 if( iter != end_it ) {
291 v = adapter_func( *iter );
300 const SubIterT subRet = iterator.iter - count;
301 return self_type( subRet, iterator.end_it, iterator.adapter_func );
308 const SubIterT subRet = iterator.iter - count;
309 return self_type( subRet, iterator.end_it, iterator.adapter_func );
312 difference_type operator-(
315 return iter - iterator.iter;
348 template<
typename SubIterT >
350 const SubIterT start,
const SubIterT end,
352 typename SubIterT::value_type(
const typename SubIterT::value_type)
362 #endif // end _H_GRB_ITERATOR_ADAPTER An iterator that simply adapts the values returned by another iterator.
Definition: adapter.hpp:68
static Adapter< SubIterT > make_adapter_iterator(const SubIterT start, const SubIterT end, const std::function< typename SubIterT::value_type(const typename SubIterT::value_type) > func)
Creates an adapter of a given iterator.
Definition: adapter.hpp:349
The sequential reference implementation.
Definition: backends.hpp:55