A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/language/../algorithm/../iterator/make_reverse_iterator.html below:

std::make_reverse_iterator - cppreference.com

(since C++14)
(constexpr since C++17)

make_reverse_iterator is a convenience function template that constructs a std::reverse_iterator for the given iterator i (which must be a LegacyBidirectionalIterator) with the type deduced from the type of the argument.

[edit] Parameters i - iterator to be converted to reverse iterator [edit] Return value

std::reverse_iterator<Iter>(i)

[edit] Notes [edit] Example
#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>
 
int main()
{
    std::vector<int> v{1, 3, 10, 8, 22};
 
    std::sort(v.begin(), v.end());
    std::copy(v.begin(), v.end(), std::ostream_iterator<int>(std::cout, ", "));
    std::cout << '\n';
 
    std::copy(std::make_reverse_iterator(v.end()),
              std::make_reverse_iterator(v.begin()),
              std::ostream_iterator<int>(std::cout, ", "));
    std::cout << '\n';
}

Output:

1, 3, 8, 10, 22,
22, 10, 8, 3, 1,
[edit] See also iterator adaptor for reverse-order traversal
(class template) [edit] returns a reverse iterator to the beginning of a container or array
(function template) [edit] returns a reverse end iterator for a container or array
(function template) [edit]

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4