std::move_iterator<Iter>::operator[]
/* unspecified */ operator[]( difference_type n ) const;
|
(constexpr seit C++17) (bis C++20) |
|
constexpr reference operator[]( difference_type n ) const;
|
(seit C++20) | |
Gibt eine Referenz auf das Element an der angegebenen relativen Position zurück.
Parameter
| n | - | Position relativ zum aktuellen Standort |
Rückgabewert
std
::
move
(
current
[
n
]
)
(bis C++20)
ranges::
iter_move
(
current
+
n
)
(seit C++20)
Hinweise
|
Der Rückgabetyp ist nicht spezifiziert, weil der Rückgabetyp des zugrundeliegenden Iterators operator [ ] ebenfalls nicht spezifiziert ist (siehe LegacyRandomAccessIterator ). |
(bis C++20) |
Beispiel
#include <cstddef>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <string>
#include <vector>
void print(auto rem, const auto& v)
{
for (std::cout << rem; const auto& e : v)
std::cout << std::quoted(e) << ' ';
std::cout << '\n';
}
int main()
{
std::vector<std::string> p{"alpha", "beta", "gamma", "delta"}, q;
print("1) p: ", p);
std::move_iterator it{p.begin()};
for (std::size_t t{}; t != p.size(); ++t)
q.emplace_back(it[t]);
print("2) p: ", p);
print("3) q: ", q);
std::list l{1, 2, 3};
std::move_iterator it2{l.begin()};
// it2[1] = 13; // Compilation error: the underlying iterator
// does not model the random access iterator
// *it2 = 999; // Compilation error: using rvalue as lvalue
}
Mögliche Ausgabe:
1) p: "alpha" "beta" "gamma" "delta"
2) p: "" "" "" ""
3) q: "alpha" "beta" "gamma" "delta"
Siehe auch
|
greift auf das referenzierte Element zu
(öffentliche Elementfunktion) |