Przejdź do głównej zawartości

std::span rbegin() method

constexpr iterator rbegin() const noexcept;

Returns a reverse iterator

to the first element of the reversed view.
It corresponds to the last element of the non reversed view.

If the span is empty, the returned iterator will be equal to rend().

zanotuj

This method doesn't actually reverse the view, it returns an iterator that points to the last element of the view, and which +, -, --, ++ operators have slightly changed implementations.

For example it++ decrements the internal pointer and it-- increments it (so that traversing the container in a reverse order actually works).

Parameters

(none)

Return value

Reverse iterator to the first element.

Complexity

Constant - O(1).

Example

Main.cpp
#include <algorithm>
#include <iostream>
#include <iterator>
#include <span>

int main()
{
constexpr std::span<const char> code{ "@droNE_T0P_w$s@s#_SECRET_a,p^42!" };

auto hacker = [](const unsigned O) { return O-0141<120; };

std::copy_if(code.rbegin(), code.rend(),
std::ostream_iterator<const char>(std::cout), hacker);
}
Output
password
This article originates from this CppReference page. It was likely altered for improvements or editors' preference. Click "Edit this page" to see all changes made to this document.
Hover to see the original license.

std::span rbegin() method

constexpr iterator rbegin() const noexcept;

Returns a reverse iterator

to the first element of the reversed view.
It corresponds to the last element of the non reversed view.

If the span is empty, the returned iterator will be equal to rend().

zanotuj

This method doesn't actually reverse the view, it returns an iterator that points to the last element of the view, and which +, -, --, ++ operators have slightly changed implementations.

For example it++ decrements the internal pointer and it-- increments it (so that traversing the container in a reverse order actually works).

Parameters

(none)

Return value

Reverse iterator to the first element.

Complexity

Constant - O(1).

Example

Main.cpp
#include <algorithm>
#include <iostream>
#include <iterator>
#include <span>

int main()
{
constexpr std::span<const char> code{ "@droNE_T0P_w$s@s#_SECRET_a,p^42!" };

auto hacker = [](const unsigned O) { return O-0141<120; };

std::copy_if(code.rbegin(), code.rend(),
std::ostream_iterator<const char>(std::cout), hacker);
}
Output
password
This article originates from this CppReference page. It was likely altered for improvements or editors' preference. Click "Edit this page" to see all changes made to this document.
Hover to see the original license.