[stacktrace.basic.cons] # 19 Diagnostics library [[diagnostics]](./#diagnostics) ## 19.6 Stacktrace [[stacktrace]](stacktrace#basic.cons) ### 19.6.4 Class template basic_stacktrace [[stacktrace.basic]](stacktrace.basic#cons) #### 19.6.4.2 Creation and assignment [stacktrace.basic.cons] [🔗](#lib:current,basic_stacktrace) `static basic_stacktrace current(const allocator_type& alloc = allocator_type()) noexcept; ` [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1982) *Returns*: A basic_stacktrace object with *frames_* storing the stacktrace of the current evaluation in the current thread of execution, or an empty basic_stacktrace object if the initialization of *frames_* failed[.](#1.sentence-1) alloc is passed to the constructor of the *frames_* object[.](#1.sentence-2) [*Note [1](#note-1)*: If the stacktrace was successfully obtained, then *frames_*.front() is the stacktrace_entry representing approximately the current evaluation, and*frames_*.back() is the stacktrace_entry representing approximately the initial function of the current thread of execution[.](#1.sentence-3) — *end note*] [🔗](#lib:current,basic_stacktrace_) `static basic_stacktrace current(size_type skip, const allocator_type& alloc = allocator_type()) noexcept; ` [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L2008) Let t be a stacktrace as-if obtained via basic_stacktrace​::​current(alloc)[.](#2.sentence-1) Let n be t.size()[.](#2.sentence-2) [3](#3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L2013) *Returns*: A basic_stacktrace object where *frames_* is direct-non-list-initialized from argumentst.begin() + min(n, skip), t.end(), and alloc, or an empty basic_stacktrace object if the initialization of *frames_* failed[.](#3.sentence-1) [🔗](#lib:current,basic_stacktrace__) `static basic_stacktrace current(size_type skip, size_type max_depth, const allocator_type& alloc = allocator_type()) noexcept; ` [4](#4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L2029) Let t be a stacktrace as-if obtained via basic_stacktrace​::​current(alloc)[.](#4.sentence-1) Let n be t.size()[.](#4.sentence-2) [5](#5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L2034) *Hardened preconditions*: skip <= skip + max_depth is true[.](#5.sentence-1) [6](#6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L2038) *Returns*: A basic_stacktrace object where *frames_* is direct-non-list-initialized from argumentst.begin() + min(n, skip), t.begin() + min(n, skip + max_depth), and alloc, or an empty basic_stacktrace object if the initialization of *frames_* failed[.](#6.sentence-1) [🔗](#lib:basic_stacktrace,constructor) `basic_stacktrace() noexcept(is_nothrow_default_constructible_v); ` [7](#7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L2054) *Postconditions*: empty() is true[.](#7.sentence-1) [🔗](#lib:basic_stacktrace,constructor_) `explicit basic_stacktrace(const allocator_type& alloc) noexcept; ` [8](#8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L2065) *Effects*: alloc is passed to the *frames_* constructor[.](#8.sentence-1) [9](#9) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L2069) *Postconditions*: empty() is true[.](#9.sentence-1) [🔗](#lib:basic_stacktrace,constructor__) `basic_stacktrace(const basic_stacktrace& other); basic_stacktrace(const basic_stacktrace& other, const allocator_type& alloc); basic_stacktrace(basic_stacktrace&& other, const allocator_type& alloc); basic_stacktrace& operator=(const basic_stacktrace& other); basic_stacktrace& operator=(basic_stacktrace&& other) noexcept(allocator_traits::propagate_on_container_move_assignment::value || allocator_traits::is_always_equal::value); ` [10](#10) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L2087) *Remarks*: Implementations may strengthen the exception specification for these functions ([[res.on.exception.handling]](res.on.exception.handling "16.4.6.14 Restrictions on exception handling")) by ensuring that empty() is true on failed allocation[.](#10.sentence-1)