- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
#include <vector>
#include <iostream>
template<class T>
struct reverse_view_impl {
const T& cont;
reverse_view_impl(const T& cont): cont(cont) {}
using iterator = typename T::const_reverse_iterator;
};
template<class T>
reverse_view_impl<T> reverse_view(const T& cont) {
return reverse_view_impl<T>(cont);
}
template<class T>
typename reverse_view_impl<T>::iterator begin(const reverse_view_impl<T>& view) {
return view.cont.crbegin();
}
template<class T>
typename reverse_view_impl<T>::iterator end(const reverse_view_impl<T>& view) {
return view.cont.crend();
}
std::vector<int> one_two_three() { return { 1, 2, 3 }; }
int main() {
for (auto i : reverse_view(one_two_three())) {
std::cout << i << std::endl;
}
}