Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::make_move_iterator

      From cppreference.com
      <cpp‎ |iterator
       
       
      Iterator library
      Iterator concepts
      Iterator primitives
      Algorithm concepts and utilities
      Indirect callable concepts
      Common algorithm requirements
      (C++20)
      (C++20)
      (C++20)
      Utilities
      (C++20)
      Iterator adaptors
      Range access
      (C++11)(C++14)
      (C++14)(C++14)  
      (C++11)(C++14)
      (C++14)(C++14)  
      (C++17)(C++20)
      (C++17)
      (C++17)
       
      Defined in header<iterator>
      template<class Iter>
      std::move_iterator<Iter> make_move_iterator( Iter i);
      (since C++11)
      (constexpr since C++17)

      make_move_iterator is a convenience function template that constructs astd::move_iterator for the given iteratori with the type deduced from the type of the argument.

      Contents

      [edit]Parameters

      i - input iterator to be converted to move iterator

      [edit]Return value

      std::move_iterator<Iter>(std::move(i))

      [edit]Example

      Run this code
      #include <iomanip>#include <iostream>#include <iterator>#include <list>#include <string>#include <vector> auto print=[](constauto rem,constauto& seq){for(std::cout<< rem;constauto& str: seq)std::cout<<std::quoted(str)<<' ';std::cout<<'\n';}; int main(){std::list<std::string> s{"one","two","three"}; std::vector<std::string> v1(s.begin(), s.end());// copy std::vector<std::string> v2(std::make_move_iterator(s.begin()),                                std::make_move_iterator(s.end()));// move     print("v1 now holds: ", v1);    print("v2 now holds: ", v2);    print("original list now holds: ", s);}

      Possible output:

      v1 now holds: "one" "two" "three" v2 now holds: "one" "two" "three" original list now holds: "" "" ""

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 2061C++11make_move_iterator did not convert array arguments to pointersmade to convert

      [edit]See also

      iterator adaptor which dereferences to an rvalue
      (class template)[edit]
      (C++11)
      converts the argument to an xvalue
      (function template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/iterator/make_move_iterator&oldid=177532"

      [8]ページ先頭

      ©2009-2025 Movatter.jp