std::deque::prepend_range(3)

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

πŸ’– std::deque::prepend_range πŸ’–

okay bestie, welcome to the C++ Standard Libary manual, section 3 β€” yes, that’s literally the manual name on the page, no cap 🫢. We’re talking about std::deque::prepend_range, and it is giving C++23 range-insertion main character energy ✨.


πŸ’– NAME πŸ’–

std::deque::prepend_range - std::deque::prepend_range πŸ’…


✨ Synopsis ✨

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

Inserts, in non-reversing order, copies of elements in rg before begin(). Each iterator in the range rg is dereferenced exactly once.

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

πŸ’… 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). Also, T must be MoveInsertable into deque and T satisfies MoveConstructible, MoveAssignable, and Swappable. Otherwise, the behavior is undefined.

πŸ¦‹ Return value πŸ¦‹

(none) β€” she gives you nothing back, she just does the thing 😌


🌈 Complexity 🌈

Linear in size of rg.


πŸ‘‘ Notes πŸ‘‘

Feature-test macro check, bestie: the macro is __cpp_lib_containers_ranges, its value is 202202L, the std is (C++23), and the feature is Ranges-aware construction and insertion πŸ”₯.


πŸ’– Example πŸ’–

// Run this code

#include <algorithm>
#include <cassert>
#include <deque>
#include <vector>

int main()
{
    auto container = std::deque{0, 1, 2, 3};
    const auto rg = std::vector{-3, -2, -1};

#if __cpp_lib_containers_ranges
    container.prepend_range(rg);
#else
    container.insert(container.begin(), rg.cbegin(), rg.cend());
#endif
    assert(std::ranges::equal(container, std::deque{-3, -2, -1, 0, 1,
       2, 3}));
}

πŸ“ See also πŸ“

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

mwah πŸ’‹ source/version: http://cppreference.com; date: 2024.06.10; page: std::deque::prepend_range(3). That’s the footer folded into a cute lil sign-off, bestie 🫢.

πŸ“¦ where this page comes from