std::move_iterator<Iter>:: operator[]
| Iterator concepts | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Iterator primitives | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Algorithm concepts and utilities | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Indirect callable concepts | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Common algorithm requirements | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Utilities | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Iterator adaptors | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||
|
move_iterator::operator[]
|
||||
| Non-member functions | ||||
|
(until C++20)
(C++20)
|
||||
|
(C++20)
|
||||
|
(C++20)
|
||||
|
(C++20)
|
||||
|
(C++20)
|
||||
|
(C++11)
|
|
/* unspecified */
operator
[
]
(
difference_type n
)
const
;
|
(constexpr начиная с C++17)
(до C++20) |
|
|
constexpr
reference operator
[
]
(
difference_type n
)
const
;
|
(начиная с C++20) | |
Возвращает ссылку на элемент в указанном относительном местоположении.
Содержание |
Параметры
| n | - | позиция относительно текущего местоположения |
Возвращаемое значение
std
::
move
(
current
[
n
]
)
(до C++20)
ranges::
iter_move
(
current
+
n
)
(начиная с C++20)
Примечания
|
Возвращаемый тип не указан, поскольку возвращаемый тип operator [ ] базового итератора также не указан (см. LegacyRandomAccessIterator ). |
(until C++20) |
Пример
#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; // Ошибка компиляции: базовый итератор // не реализует концепцию random access iterator // *it2 = 999; // Ошибка компиляции: использование rvalue как lvalue }
Возможный вывод:
1) p: "alpha" "beta" "gamma" "delta" 2) p: "" "" "" "" 3) q: "alpha" "beta" "gamma" "delta"
Смотрите также
|
обращается к указываемому элементу
(public member function) |