Defined in header <iterator> | ||
---|---|---|
template <class Iterator> std::reverse_iterator<Iterator> make_reverse_iterator( Iterator i ); | (since C++14) (until C++17) | |
template <class Iterator> constexpr std::reverse_iterator<Iterator> make_reverse_iterator( Iterator i ); | (since C++17) |
make_reverse_iterator
is a convenience function template that constructs a std::reverse_iterator
for the given iterator i
with the type deduced from the type of the argument.
i | - | input iterator to be converted to reverse iterator |
A std::reverse_iterator
constructed from i
.
template< class Iterator > std::reverse_iterator<Iterator> make_reverse_iterator( Iterator i ) { return std::reverse_iterator<Iterator>(i); } |
#include <iostream> #include <iterator> #include <vector> #include <algorithm> int main() { auto v = std::vector<int>{ 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, ", ")); }
Output:
1, 3, 8, 10, 22, 22, 10, 8, 3, 1,
iterator adaptor for reverse-order traversal (class template) |
|
(C++14) | returns a reverse iterator to a container or array (function) |
(C++14) | returns a reverse end iterator for a container or array (function) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/iterator/make_reverse_iterator