std::make_reverse_iterator(3)
β¨ std::make_reverse_iterator β¨
okay so bestie, welcome to the C++ Standard Library manual page for std::make_reverse_iterator β yes, that's the whole NAME section, it's literally just std::make_reverse_iterator twice, iconic minimalism honestly π
π Synopsis π
Defined in header <iterator>
template< class Iter > (since C++14)
std::reverse_iterator<Iter> make_reverse_iterator( Iter i );
(constexpr since C++17)
So like. make_reverse_iterator is a convenience function template that constructs a std::reverse_iterator for the iterator i you hand it β and i must be a LegacyBidirectionalIterator, no exceptions, that's the vibe check it has to pass β with the type deduced from the type of the argument. Deduction queen behavior fr fr π«Ά
πΈ Parameters πΈ
iβ the iterator being converted into a reverse iterator. that's it. that's the whole parameter list. she's low maintenance π
π¦ Return value π¦
A std::reverse_iterator constructed from i. slay, that's the whole deal β¨
β Notes β
there's a feature-test macro you can check, and here's the tea:
- Feature-test macro:
__cpp_lib_make_reverse_iterator - Value:
201402L(C++14) - Feature:
std::make_reverse_iterator
ngl knowing this macro exists is such main character energy π
π Possible implementation π
like, this is what it could look like under the hood, and it's giving "so simple it's almost rude":
template<class Iter>
constexpr std::reverse_iterator<Iter> make_reverse_iterator(Iter i)
{
return std::reverse_iterator<Iter>(i);
}
one-line body. one singular return. ate and left no crumbs π₯
π Example π
// Run this code β go on, run it, I'll wait π§
#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,
notice how we're passing v.end() first and v.begin() second? that's the reverse-iterator moment bestie, that's the whole personality ππ
π See also π
reverse_iteratorβ iterator adaptor for reverse-order traversal (class template)rbeginβ returns a reverse iterator to the beginning of a container or array (function template) (C++14)crbeginβ (function template) (C++14)rendβ returns a reverse end iterator for a container or array (function template) (C++14)crendβ (function template) (C++14)
heads up bestie: thec-prefixed ones (crbegin,crend) show up as plain(function template)(C++14)in the original page, so that's exactly how I'm giving them to you β no invented descriptions, no cap π
and that's the page!! brought to you by http://cppreference.com, version 2024.06.10 β yell at them, not me, if anything's weird. mwah πβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms