std::list::assign_range(3)

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

✨ NAME ✨

std::list::assign_range β€” std::list::assign_range. That’s the whole NAME, bestie. This is the std::list::assign_range(3) page from the C++ Standard Libary (yes, that’s how the manual name is spelled here πŸ’…).


🌸 Synopsis 🌸

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

Ok so picture this: assign_range replaces the elements in the container with a copy of each element in rg. That’s the main-character move. ✨

It invalidates all iterators, pointers and references to the elements. All of them. No survivors, bestie 😭.

Each iterator in the range rg is dereferenced exactly once. Periodt.

⚠️ The behavior is undefined if rg overlaps with the container. Like, do not do that. 🫢

πŸŽ€ Parameters πŸŽ€

  • rg β€” an input_range with reference type convertible to the element type of the container.

🧚 Type requirements 🧚

  • std::assignable_from<T&, ranges::range_reference_t<R>> must be modeled. Otherwise, the program is ill-formed.
  • T must be EmplaceConstructible into the container from *ranges::begin(rg). Otherwise, the behavior is undefined.

πŸ’« Return value πŸ’«

(none) β€” literally nothing returned, bestie.


πŸ“ Notes πŸ“

Feature-test macro check, iykyk πŸ‘‘

  • Feature-test macro: __cpp_lib_containers_ranges
  • Value: 202202L
  • Std: (C++23)
  • Feature: Ranges-aware construction and insertion

πŸ’» Example πŸ’»

Run this code, bestie:

// Run this code

#include <algorithm>
#include <cassert>
#include <list>
#include <vector>

int main()
{
    const auto source = std::vector{2, 7, 1};
    auto destination = std::list{3, 1, 4};
#ifdef __cpp_lib_containers_ranges
    destination.assign_range(source);
#else
    destination.assign(source.cbegin(), source.cend());
#endif
    assert(std::ranges::equal(source, destination));
}

πŸ‘€ See also πŸ‘€

  • insert_range β€” inserts a range of elements; (C++23); public member function.
  • prepend_range β€” adds a range of elements to the beginning; (C++23); public member function.
  • append_range β€” adds a range of elements to the end; (C++23); public member function.
  • assign β€” assigns values to the container; public member function.

That’s the whole page, bestie πŸ’– β€” source/version: http://cppreference.com, date: 2024.06.10, page: std::list::assign_range(3). bye πŸ¦‹πŸŽ€

πŸ“¦ where this page comes from