std::deque::append_range(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸŽ€ std::deque::append_range(3) πŸŽ€

okay so this is the C++ Standard Libary manual page for std::deque::append_range, and bestie, it's giving C++23 range-insertion era ✨.


🌸 NAME 🌸

std::deque::append_range β€” and the NAME line is literally std::deque::append_range - std::deque::append_range, no cap 😭.

✨ Synopsis ✨

template< container-compatible-range<T> R >  (since C++23)
void append_range( R&& rg );

It inserts copies of elements from the range rg before end(), in non-reversing order πŸ’….

All iterators (including the end() iterator) are invalidated. No references are invalidated.

Each iterator in rg is dereferenced exactly once. Slay, efficient little range.

πŸ’– Parameters πŸ’–

  • rg β€” a container compatible range, that is, an input_range whose elements are convertible to T.

πŸ¦‹ Type requirements πŸ¦‹

  • T must be EmplaceConstructible into deque from *ranges::begin(rg). Otherwise, the behavior is undefined.
🚨 undefined behavior alert, bestie β€” this is not a vibe you want to f around with.

🌈 Return value 🌈

(none) β€” literally nothing, she just does the insertion and leaves πŸ‘‘.

πŸ”₯ Complexity πŸ”₯

Linear in size of rg πŸ”₯. The number of calls to the constructor of T is exactly equal to the std::ranges::size(rg)).

πŸ’€ Exceptions πŸ’€

  • If an exception is thrown other than by the copy constructor, move constructor, assignment operator, or move assignment operator of T, there are no effects.
  • If an exception is thrown while inserting a single element at either end, there are no effects.
  • Otherwise, if an exception is thrown by the move constructor of a non-CopyInsertable T, the effects are unspecified.
πŸ’€ β€œunspecified” is doing a lot of heavy lifting there β€” keep that caveat in mind.

πŸ“ Notes πŸ“

  • __cpp_lib_containers_ranges β€” value 202202L, std C++23, feature: Ranges-aware construction and insertion ✨.

🧚 Example 🧚

// Run this code

#include <algorithm>
#include <cassert>
#include <deque>
#include <list>

int main()
{
    auto head = std::deque{1, 2, 3, 4};
    const auto tail = std::list{-5, -6, -7};
#ifdef __cpp_lib_containers_ranges
    head.append_range(tail);
#else
    head.insert(head.end(), tail.cbegin(), tail.cend());
#endif
    assert(std::ranges::equal(head, std::deque{1, 2, 3, 4, -5, -6, -7}));
}

πŸ‘‘ See also πŸ‘‘

  • prepend_range β€” adds a range of elements to the beginning (C++23) (public member function)
  • insert_range β€” inserts a range of elements (C++23) (public member function)
  • push_back β€” adds an element to the end (public member function)
  • emplace_back β€” constructs an element in-place at the end (C++11) (public member function)

mwah πŸ’‹ β€” source: http://cppreference.com, version/date: 2024.06.10 🫢

πŸ“¦ where this page comes from