#
reverse_view takes a bidirectional view and produces another view that iterates the same elements in reverse order.
2
#
The name views​::​reverse denotes a range adaptor object ([range.adaptor.object]).
Given a subexpression E, the expression views​::​reverse(E) is expression-equivalent to:
  • If the type of E is a (possibly cv-qualified) specialization of reverse_view, then E.base().
  • Otherwise, if E is a specialization of optional and E models view, then decay-copy(E).
  • Otherwise, if the type of E is cv subrange<reverse_iterator<I>, reverse_iterator<I>, K> for some iterator type I and value K of type subrange_kind,
    • if K is subrange_kind​::​sized, then subrange<I, I, K>(E.end().base(), E.begin().base(), E.size();
    • otherwise, subrange<I, I, K>(E.end().base(), E.begin().base().
    However, in either case E is evaluated only once.
  • Otherwise, reverse_view{E}.
[Example 1: vector<int> is {0,1,2,3,4}; for (int i : is | views::reverse) cout << i << ' '; / prints 4 3 2 1 0 — end example]

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant