Radium Engine  1.5.20
Loading...
Searching...
No Matches
Iterators.hpp
1#pragma once
2
3namespace Ra {
4namespace Core {
5
6namespace _internalIterator {
7template <class T>
8struct _reversed {
9 T& t;
10 explicit _reversed( T& _t ) : t( _t ) {}
11};
12template <class T>
13struct _creversed {
14 const T& t;
15 explicit _creversed( const T& _t ) : t( _t ) {}
16};
17} // namespace _internalIterator
18
19// Provide reverse iterators for range loops and std::containers:
20// \code for (auto x: reversed(c)) ; \endcode
21// source: https://stackoverflow.com/a/21510185
22template <class T>
23_internalIterator::_reversed<T> reversed( T& t ) {
24 return _internalIterator::_reversed<T>( t );
25}
26template <class T>
27_internalIterator::_reversed<T const> reversed( T const& t ) {
28 return _internalIterator::_reversed<T const>( t );
29}
30} // namespace Core
31} // namespace Ra
32
33namespace std {
34template <class T>
35auto begin( Ra::Core::_internalIterator::_reversed<T>& r ) -> decltype( r.t.rbegin() ) {
36 return r.t.rbegin();
37}
38template <class T>
39auto end( Ra::Core::_internalIterator::_reversed<T>& r ) -> decltype( r.t.rend() ) {
40 return r.t.rend();
41}
42
43template <class T>
44auto begin( Ra::Core::_internalIterator::_creversed<T> const& cr ) -> decltype( cr.t.rbegin() ) {
45 return cr.t.rbegin();
46}
47template <class T>
48auto end( Ra::Core::_internalIterator::_creversed<T> const& cr ) -> decltype( cr.t.rend() ) {
49 return cr.t.rend();
50}
51} // namespace std
T begin(T... args)
T end(T... args)
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:3
STL namespace.