1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-27 02:23:26 +03:00

utils: Add reversed template helper for container iteration

this permits to use range-based for loops to iterate on reversed
containers. Should work on any container implementing rbegin and rend.
This commit is contained in:
Maxime Coste 2011-09-06 18:33:35 +00:00
parent 3f51feaaef
commit f58cbf0b98

View File

@ -13,6 +13,24 @@ struct LineAndColumn
: line(line), column(column) {}
};
template<typename Container>
struct ReversedContainer
{
ReversedContainer(Container& container) : container(container) {}
Container& container;
decltype(container.rbegin()) begin() { return container.rbegin(); }
decltype(container.rend()) end() { return container.rend(); }
};
template<typename Container>
ReversedContainer<Container> reversed(Container& container)
{
return ReversedContainer<Container>(container);
}
}
#endif // utils_hh_INCLUDED