1 #ifndef GENESIS_UTILS_CONTAINERS_TRANSFORM_ITERATOR_H_
2 #define GENESIS_UTILS_CONTAINERS_TRANSFORM_ITERATOR_H_
38 #include <type_traits>
103 template<
typename TransformFunctor,
typename BaseIterator >
114 TransformFunctor(
typename std::iterator_traits<BaseIterator>::reference )
126 std::is_reference<result_type>::value, bool,
result_type
134 using return_type =
typename std::remove_reference<result_type>::type;
168 : functor_( unary_func )
169 , current_( iterator )
209 return get_value_<result_type>();
214 return &get_value_<result_type>();
234 cache_valid_ =
false;
241 cache_valid_ =
false;
261 return { current_ + n, functor_ };
266 return { current_ - n, functor_ };
272 cache_valid_ =
false;
279 cache_valid_ =
false;
294 return current_ - it.current_;
303 return current_ == it.current_;
308 return !(*
this == it);
313 return *
this - it < 0;
323 return !(*
this > it);
328 return !(*
this < it);
340 template<typename T, typename std::enable_if< std::is_reference<T>::value >::type* =
nullptr>
346 std::is_same<T, result_type>::value,
"Function has to be called using T=result_type"
351 std::is_reference<result_type>::value,
352 "Function SFINAE is activated although result_type is not a reference type"
355 std::is_same<cache_type, bool>::value,
356 "cache_type is not bool although result_type is a reference type"
360 return functor_( *current_ );
366 template<typename T, typename std::enable_if< !std::is_reference<T>::value >::type* =
nullptr>
372 std::is_same<T, result_type>::value,
"Function has to be called using T=result_type"
377 ! std::is_reference<result_type>::value,
378 "Function SFINAE is activated although result_type is a reference type"
381 std::is_same<cache_type, result_type>::value,
382 "cache_type is not the same as result_type although result_type is a not reference type"
386 if( ! cache_valid_ ) {
387 cache_ = functor_( *current_ );
399 TransformFunctor functor_;
400 BaseIterator current_;
409 mutable bool cache_valid_ =
false;
425 template<
typename TransformFunctor,
typename BaseIterator>
427 TransformFunctor unary_func,
428 BaseIterator iterator
437 template<
typename TransformFunctor,
typename BaseIterator>
439 TransformFunctor unary_func,
453 template<
typename TransformFunctor,
typename Container>
455 TransformFunctor unary_func,
460 unary_func, container.begin()
463 unary_func, container.end()
472 template<
typename TransformFunctor,
typename Container>
474 TransformFunctor unary_func,
475 Container
const& container
479 unary_func, container.begin()
482 unary_func, container.end()
490 #endif // include guard