std::basic_...ktrace::swap(3)
π 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β thebasic_stacktraceyou 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 thestd::swapalgorithm (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
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms