Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::inplace_vector<T,N>::insert_range

      From cppreference.com
      <cpp‎ |container‎ |inplace vector

      [edit template]
       
       
       
      std::inplace_vector
      Member types
      Member functions
      Non-member functions
       
      template<container-compatible-range<T> R>
      constexpr iterator insert_range( const_iterator pos, R&& rg);
      (since C++26)

      Inserts, in non-reversing order, copies of elements inrg beforepos.

      This section is incomplete

      Each iterator in the rangerg is dereferenced exactly once.

      Ifrg overlaps with*this, the behavior is undefined.

      Contents

      [edit]Parameters

      pos - iterator before which the content will be inserted (pos may be theend() iterator)
      rg - acontainer compatible range, that is, aninput_range whose elements are convertible toT
      Type requirements
      -
      If any of the following conditions is satisfied, the behavior is undefined:

      [edit]Return value

      An iterator to the first element inserted into*this, orpos ifrg is empty.

      Exceptions

      • std::bad_alloc, ifranges::distance(rg)+ size()> capacity(). The elements of*this are not modified.
      • Any exception thrown by insertion (i.e. by copy/move constructor, move/copy assignment operator ofT) or by anyLegacyInputIterator operation. The elements of*this in the range[0pos) are not modified.

      [edit]Example

      Run this code
      #include <cassert>#include <inplace_vector>#include <iterator>#include <new>#include <print> int main(){auto v=std::inplace_vector<int,8>{0,1,2,3};auto pos=std::next(v.begin(),2);assert(*pos==2);constauto rg={-1,-2,-3};    v.insert_range(pos, rg);std::println("{}", v); try{assert(v.size()+ rg.size()> v.capacity());        v.insert_range(pos, rg);// throws: no space}catch(conststd::bad_alloc& ex){std::println("{}", ex.what());}}

      Possible output:

      [0, 1, -1, -2, -3, 2, 3]std::bad_alloc

      [edit]See also

      inserts elements
      (public member function)
      adds a range of elements to the end
      (public member function)
      tries to add a range of elements to the end
      (public member function)
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/container/inplace_vector/insert_range&oldid=175337"

      [8]ページ先頭

      ©2009-2026 Movatter.jp