Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

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

      From cppreference.com
      <cpp‎ |container‎ |inplace vector
       
       
       
      std::inplace_vector
      Member types
      Member functions
      Non-member functions
       
      template<container-compatible-range<T> R>
      constexpr std::ranges::borrowed_iterator_t<R> try_append_range( R&& rg);
      (since C++26)

      Appends copies of initial elements inrg beforeend(), until all elements are inserted or the internal storage is exhausted (i.e.size()== capacity() istrue).

      All iterators and references remain valid. Theend() iterator is invalidated.

      Each iterator inrg is dereferenced at most once.

      Contents

      [edit]Parameters

      rg - acontainer compatible range, that is, aninput_range whose elements are convertible toT
      Type requirements
      -
      T must beEmplaceConstructible intoinplace_vector from*ranges::begin(rg). Otherwise, the behavior is undefined.

      [edit]Return value

      An iterator pointing to the first element ofrg that was not inserted into*this, orranges::end(rg) if no such element exists.

      [edit]Complexity

      Linear in the number of elements inserted.

      [edit]Exceptions

      Any exception thrown by initialization of inserted element.

      inplace_vector provides thebasic exception safety guarantee, i.e., all elements of the container before the call are preserved, and all already inserted elements (before the exception, if any) are also preserved.

      [edit]Notes

      This section is incomplete
      Reason: Explain the purpose of this API.

      [edit]Example

      Run this code
      #include <cassert>#include <initializer_list>#include <inplace_vector> int main(){using I=std::inplace_vector<int,8>;auto nums= I{1,2,3};constauto rg={-1,-2,-3}; auto it= nums.try_append_range(rg);assert(nums.size()==6);assert((nums== I{1,2,3,-1,-2,-3}));assert(it== rg.end());     it= nums.try_append_range(rg);assert(nums.size()==8);assert((nums== I{1,2,3,-1,-2,-3,-1,-2}));assert(it== rg.begin()+2);}

      [edit]See also

      adds a range of elements to the end
      (public member function)[edit]
      adds an element to the end
      (public member function)[edit]
      tries to add an element to the end
      (public member function)[edit]
      unconditionally adds an element to the end
      (public member function)[edit]
      constructs an element in-place at the end
      (public member function)[edit]
      tries to construct an element in-place at the end
      (public member function)[edit]
      unconditionally constructs an element in-place at the end
      (public member function)[edit]
      removes the last element
      (public member function)[edit]
      creates astd::back_insert_iterator of type inferred from the argument
      (function template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/container/inplace_vector/try_append_range&oldid=175514"

      [8]ページ先頭

      ©2009-2025 Movatter.jp