FreeBSD Manual Pages
std::move_iterator(3) C++ Standard Libary std::move_iterator(3) NAME std::move_iterator - std::move_iterator Synopsis Defined in header <iterator> template< class Iter > (since C++11) class move_iterator; std::move_iterator is an iterator adaptor which behaves exactly like the underlying iterator (which must be at least an LegacyInputIterator or model input_iterator (since C++20)), except that dereferencing converts the value re- turned by the underlying iterator into an rvalue. If this iterator is used as an input iterator, the effect is that the values are moved from, rather than copied from. Member types Member type Definition iterator_type Iter std::iterator_traits<Iter>::iterator_cate- gory (until C++20) If std::iterator_traits<Iter>::iterator_cat- egory is valid and denotes a type: * if std::iterator_traits<Iter>::itera- tor_category models iterator_category std::derived_from<std::random_access_it- erator_tag>, (since member iterator_category is C++20) std::random_access_iterator_tag. * Otherwise, member iterator_category is the same type as std::iterator_traits<Iter>::itera- tor_category. Otherwise, there is no member iterator_cate- gory. iterator_concept(C++20) std::input_iterator_tag value_type std::iterator_traits<Iter>::value_type (un- til C++20) std::iter_value_t<Iter> (since C++20) difference_type std::iterator_traits<Iter>::difference_type (until C++20) std::iter_difference_t<Iter> (since C++20) pointer Iter If std::iterator_traits<Iter>::reference is a reference, this is the rvalue reference ver- sion of the (until same type. Otherwise (such as if the wrapped iterator C++20) reference returns by value), this is std::iterator_traits<Iter>::reference un- changed std::iter_rvalue_reference_t<Iter> (since C++20) Member functions constructor constructs a new iterator adaptor (C++11) (public member function) operator= assigns another iterator adaptor (C++11) (public member function) base accesses the underlying iterator (C++11) (public member function) operator* operator-> accesses the pointed-to element (C++11) (public member function) (C++11)(deprecated in C++20) operator[] accesses an element by index (C++11) (public member function) operator++ operator++(int) operator+= operator+ advances or decrements the iterator operator-- (public member function) operator--(int) operator-= operator- (C++11) Member objects Member name Definition the underlying iterator from which base() copies current (private) or moves (since C++20), the name is for exposition only Non-member functions operator== operator!= operator< operator<= operator> operator>= operator<=> compares the underlying iterators (C++11) (function template) (C++11)(removed in C++20) (C++11) (C++11) (C++11) (C++11) (C++20) operator==(std::move_sentinel) compares the underlying iterator and the underlying (C++20) sentinel (function template) operator+ advances the iterator (C++11) (function template) operator- computes the distance between two it- erator adaptors (C++11) (function template) operator-(std::move_sentinel) computes the distance between the un- derlying iterator (C++20) and the underlying sentinel (function template) iter_move casts the result of dereferencing the underlying (C++20) iterator to its associated rvalue reference type (function) iter_swap swaps the objects pointed to by two underlying (C++20) iterators (function template) make_move_iterator creates a std::move_iterator of type inferred from (C++11) the argument (function template) Example // Run this code #include <iostream> #include <iomanip> #include <algorithm> #include <vector> #include <iterator> #include <numeric> #include <string> int main() { std::vector<std::string> v{"this", "_", "is", "_", "an", "_", "ex- ample"}; auto print_v = [&](auto const rem) { std::cout << rem; for (const auto& s : v) std::cout << std::quoted(s) << ' '; std::cout << '\n'; }; print_v("Old contents of the vector: "); std::string concat = std::accumulate(std::make_move_iterator(v.be- gin()), std::make_move_itera- tor(v.end()), std::string()); /* An alternative that uses std::move_iterator directly could be: using moviter_t = std::move_iterator<std::vector<std::string>::it- erator>; std::string concat = std::accumulate(moviter_t(v.begin()), moviter_t(v.end()), std::string()); */ print_v("New contents of the vector: "); std::cout << "Concatenated as string: " << quoted(concat) << '\n'; } Possible output: Old contents of the vector: "this" "_" "is" "_" "an" "_" "example" New contents of the vector: "" "" "" "" "" "" "" Concatenated as string: "this_is_an_example" Defect reports The following behavior-changing defect reports were applied retroac- tively to previously published C++ standards. DR Applied Behavior as Correct behavior to published dereferencing a move_iterator could return a dangling reference LWG 2106 C++11 if the returns the object instead dereferencing the underlying iterator returns a prvalue member defined only if P2259R1 C++20 iterator_category std::iterator_traits<Iter>::it- erator_category is always defined exists See also make_move_iterator creates a std::move_iterator of type inferred from the argument (C++11) (function template) move_sentinel sentinel adaptor for use with std::move_iterator (C++20) (class template) http://cppreference.com 2022.07.31 std::move_iterator(3)
NAME | Synopsis | Member types | Member functions | Member objects | Non-member functions | Example | Possible output: | See also
Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=std::move_iterator&sektion=3&manpath=FreeBSD+Ports+15.0>
