标准库标头 <stacktrace> (C++23)

来自cppreference.com
< cpp‎ | header


 
 
标准库头
通用工具
<any> (C++17)
<bitset>
<bit> (C++20)
<charconv> (C++17)
<expected> (C++23)
<format> (C++20)
<functional>
<optional> (C++17)
<stdbit.h> (C++26)
<tuple> (C++11)
<typeindex> (C++11)
<utility>
<variant> (C++17)
容器
<array> (C++11)
<deque>
<flat_map> (C++23)
<flat_set> (C++23)
<forward_list> (C++11)
<hive> (C++26)
<inplace_vector> (C++26)   
<list>
<map>
<mdspan> (C++23)
<queue>
<set>
<span> (C++20)
<stack>
<unordered_map> (C++11)
<unordered_set> (C++11)
<vector>
迭代器
<iterator>
范围
<generator> (C++23)
<ranges> (C++20)
 

此头文件是诊断库的一部分。

目录

表示栈踪迹中求值的项
(类) [编辑]
由栈踪迹条目组成的调用序列的近似表示
(类模板) [编辑]
std::stacktrace_entry 的散列支持
(类模板特化) [编辑]
std::basic_stacktrace 的散列支持
(类模板特化) [编辑]
前置声明
在标头 <functional> 定义
(C++11)
散列函数对象
(类模板) [编辑]
类型别名
别名 类型
std::stacktrace std::basic_stacktrace<std::allocator<std::stacktrace_entry>>
std::pmr::stacktrace std::pmr::basic_stacktrace<
    std::pmr::polymorphic_allocator<std::stacktrace_entry>>

函数

特化 std::swap 算法
(函数模板) [编辑]
(C++23)
返回拥有 stacktrace_entry 的描述的字符串
(函数) [编辑]
(C++23)
返回拥有 basic_stacktrace 的描述的字符串
(函数模板) [编辑]
进行 stacktrace_entry 的流输出
(函数模板) [编辑]
进行 basic_stacktrace 的流输出
(函数模板) [编辑]

[编辑] 概要

namespace std {
  // 类 stacktrace_entry
  class stacktrace_entry;
 
  // 类模板 basic_stacktrace
  template<class Allocator>
    class basic_stacktrace;
 
  // basic_stacktrace typedef 名
  using stacktrace = basic_stacktrace<allocator<stacktrace_entry>>;
 
  // 非成员函数
  template<class Allocator>
    void swap(basic_stacktrace<Allocator>& a, basic_stacktrace<Allocator>& b)
      noexcept(noexcept(a.swap(b)));
 
  string to_string(const stacktrace_entry& f);
 
  template<class Allocator>
    string to_string(const basic_stacktrace<Allocator>& st);
 
  ostream& operator<<(ostream& os, const stacktrace_entry& f);
 
  template<class Allocator>
    ostream& operator<<(ostream& os, const basic_stacktrace<Allocator>& st);
 
  namespace pmr {
    using stacktrace = std::basic_stacktrace<polymorphic_allocator<stacktrace_entry>>;
  }
 
  // 散列支持
  template<class T> struct hash;
  template<> struct hash<stacktrace_entry>;
  template<class Allocator> struct hash<basic_stacktrace<Allocator>>;
}

[编辑] std::stacktrace_entry

namespace std {
  class stacktrace_entry {
  public:
    using native_handle_type = /* 由实现定义 */;
 
    // 构造函数
    constexpr stacktrace_entry() noexcept;
    constexpr stacktrace_entry(const stacktrace_entry& other) noexcept;
    constexpr stacktrace_entry& operator=(const stacktrace_entry& other) noexcept;
 
    ~stacktrace_entry();
 
    // 观察器
    constexpr native_handle_type native_handle() const noexcept;
    constexpr explicit operator bool() const noexcept;
 
    // 查询
    string description() const;
    string source_file() const;
    uint_least32_t source_line() const;
 
    // 比较
    friend constexpr bool operator==(const stacktrace_entry& x,
                                     const stacktrace_entry& y) noexcept;
    friend constexpr strong_ordering operator<=>(const stacktrace_entry& x,
                                                 const stacktrace_entry& y) noexcept;
  };
}

[编辑] 类模板 std::basic_stacktrace

namespace std {
  template<class Allocator>
  class basic_stacktrace {
  public:
    using value_type = stacktrace_entry;
    using const_reference = const value_type&;
    using reference = value_type&;
    using const_iterator = /* 由实现定义 */;
    using iterator = const_iterator;
    using reverse_iterator = std::reverse_iterator<iterator>;
    using const_reverse_iterator = std::reverse_iterator<const_iterator>;
    using difference_type = /* 由实现定义 */;
    using size_type = /* 由实现定义 */;
    using allocator_type = Allocator;
 
    // 创建与赋值
    static basic_stacktrace
      current(const allocator_type& alloc = allocator_type()) noexcept;
    static basic_stacktrace
      current(size_type skip, const allocator_type& alloc = allocator_type()) noexcept;
    static basic_stacktrace
      current(size_type skip, size_type max_depth,
              const allocator_type& alloc = allocator_type()) noexcept;
 
    basic_stacktrace() noexcept(is_nothrow_default_constructible_v<allocator_type>);
    explicit basic_stacktrace(const allocator_type& alloc) noexcept;
 
    basic_stacktrace(const basic_stacktrace& other);
    basic_stacktrace(basic_stacktrace&& other) noexcept;
    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<Allocator>::propagate_on_container_move_assignment::value ||
        allocator_traits<Allocator>::is_always_equal::value);
 
    ~basic_stacktrace();
 
    // 观察器
    allocator_type get_allocator() const noexcept;
 
    const_iterator begin() const noexcept;
    const_iterator end() const noexcept;
    const_reverse_iterator rbegin() const noexcept;
    const_reverse_iterator rend() const noexcept;
 
    const_iterator cbegin() const noexcept;
    const_iterator cend() const noexcept;
    const_reverse_iterator crbegin() const noexcept;
    const_reverse_iterator crend() const noexcept;
 
    bool empty() const noexcept;
    size_type size() const noexcept;
    size_type max_size() const noexcept;
 
    const_reference operator[](size_type) const;
    const_reference at(size_type) const;
 
    // 比较
    template<class Allocator2>
    friend bool operator==(const basic_stacktrace& x,
                           const basic_stacktrace<Allocator2>& y) noexcept;
    template<class Allocator2>
    friend strong_ordering operator<=>(const basic_stacktrace& x,
                                       const basic_stacktrace<Allocator2>& y) noexcept;
 
    // 修改器
    void swap(basic_stacktrace& other)
      noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
        allocator_traits<Allocator>::is_always_equal::value);
 
  private:
    vector<value_type, allocator_type> frames_;         // 仅用于阐述
  };
}