std::basic_...ktrace::swap(3)

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

πŸ’… std::basic_stacktrace::swap β€” bestie edition

okay so this is the std::basic_stacktrace::swap page from the C++ Standard Libary (yes the cppreference header spells it "Libary", we don't fix it, we respect it 🫢), and honestly? it's kind of a slay. it's a member function that just... trades vibes with another stacktrace. no drama, no copying, no per-element nonsense. let's get into it ✨


🌸 SYNOPSIS 🌸

void swap( basic_stacktrace& other ) noexcept(/* see below */);

(since C++23) β€” she's new here but she ate πŸ’…


πŸ’– DESCRIPTION πŸ’–

so the way this works is: it exchanges the contents of the container with those of other. that's it. that's the whole bit. mutual vibe transfer, no cap.

and here's the iconic part β€” it does not invoke any move, copy, or swap operations on individual stacktrace_entry objects. not one. zero. the entries themselves are just chilling, untouched, unbothered. main character energy on their behalf honestly ✨

All iterators and references remain valid. πŸŽ€ everything that pointed at stuff still points at stuff. BUT β€” and this is the one little plot twist β€” the end() iterator is invalidated. so like, she's still valid everywhere except the very end. we love a boundary condition 😭

ok now the allocator lore, pay attention because there's an undefined-behavior jumpscare at the end πŸ™ˆ:

if

std::allocator_traits<allocator_type>::propagate_on_container_swap::value

is true, then the allocators are exchanged, using an unqualified call to non-member swap. cute, standard, love that for them πŸ’œ

otherwise, they are not swapped β€” and if get_allocator() != other.get_allocator(), the behavior is undefined. so fr fr, check your allocators before you get messy. undefined behavior is NOT the vibe πŸ’€


πŸ¦‹ PARAMETERS πŸ¦‹

  • other β€” the basic_stacktrace you wanna exchange contents with. your swap partner in crime 🫢

πŸŽ€ RETURN VALUE πŸŽ€

(none) β€” she gives nothing back because she's already given everything. void. iconic.


πŸ”₯ EXCEPTIONS πŸ”₯

the noexcept specification is, and I quote, verbatim, no edits bestie:

noexcept(std::allocator_traits<Allocator>::propagate_on_container_swap::value
|| std::allocator_traits<Allocator>::is_always_equal::value)

so it's conditionally noexcept β€” which, yes, is literally one of the categories listed at the bottom of the page. we stay consistent πŸ’…


⭐ COMPLEXITY ⭐

Constant. O(1) baby!! she's fast, she's efficient, she does not do loops 🌈


πŸ“ EXAMPLE πŸ“

This section is incomplete Reason: no example

so yeah... there's literally no example here 😭 the page itself says it's incomplete. nothing to show you, the example section is a ghost. (this is also why she's filed under Todo no example down at the bottom, iykyk πŸ™ˆ)


🌸 SEE ALSO 🌸

  • std::swap(std::basic_stacktrace) β€” specializes the std::swap algorithm (C++23) (function template) β€” the non-member bestie who has her back πŸ’œ

πŸ‘‘ CATEGORIES πŸ‘‘

  • conditionally noexcept ✨
  • Todo no example πŸ™ˆ

k that's the whole page, every flag-free, option-free, detail-intact bit of it πŸ’– lowkey a cute little function. constant time, iterators stay valid, end() gets sacrificed for the cause, allocators get a whole conditional arc, and there's not even an example to look at yet 😭

🧚 from http://cppreference.com, dated 2024.06.10 β€” this has been your girl signing off on std::basic_...ktrace::swap(3), mwah πŸ’‹ periodt πŸŽ€

πŸ“¦ where this page comes from