1#ifndef MSTL_CORE_UTILITY_STACKTRACE_HPP__
2#define MSTL_CORE_UTILITY_STACKTRACE_HPP__
3#include "../container/vector.hpp"
4#include "../interface/istringify.hpp"
5#ifdef MSTL_PLATFORM_WINDOWS__
10class MSTL_API stacktrace :
public istringify<stacktrace> {
12 class frame :
public istringify<frame> {
16#ifdef MSTL_PLATFORM_WINDOWS__
17 static void ensure_initialized();
18 static mutex& dbghelp_mutex();
22 frame() : address_(nullptr) {}
23 explicit frame(
void* addr) : address_(addr) {}
25 MSTL_NODISCARD
void* address() const noexcept {
return address_; }
26 MSTL_NODISCARD
string name()
const;
28 MSTL_NODISCARD
bool operator ==(
const frame& other)
const noexcept {
29 return address_ == other.address_;
31 MSTL_NODISCARD
bool operator !=(
const frame& other)
const noexcept {
32 return !(*
this == other);
35 MSTL_NODISCARD
string to_string()
const;
39 vector<frame> frames_;
42 explicit stacktrace(
size_t skip = 0,
size_t max_depth = 64);
44 MSTL_NODISCARD
size_t size() const noexcept {
return frames_.size(); }
45 MSTL_NODISCARD
bool empty() const noexcept {
return frames_.empty(); }
47 MSTL_NODISCARD
const frame& operator [](
const size_t idx)
const noexcept {
return frames_[idx]; }
48 MSTL_NODISCARD frame& operator [](
const size_t idx)
noexcept {
return frames_[idx]; }
50 MSTL_NODISCARD
auto begin() const noexcept {
return frames_.begin(); }
51 MSTL_NODISCARD
auto end() const noexcept {
return frames_.end(); }
52 MSTL_NODISCARD
auto cbegin() const noexcept {
return frames_.cbegin(); }
53 MSTL_NODISCARD
auto cend() const noexcept {
return frames_.cend(); }
55 MSTL_NODISCARD
string to_string()
const;
bool operator!=(const function< Res(Args...)> &f, nullptr_t null) noexcept
不等于空指针比较
bool operator==(const function< Res(Args...)> &f, nullptr_t null) noexcept
等于空指针比较
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL
MSTL_NODISCARD MSTL_ALWAYS_INLINE constexpr bool empty(const Container &cont) noexcept(noexcept(cont.empty()))
检查容器是否为空
MSTL_NODISCARD MSTL_ALWAYS_INLINE constexpr decltype(auto) end(Container &cont) noexcept(noexcept(cont.end()))
获取容器的结束迭代器
MSTL_NODISCARD MSTL_ALWAYS_INLINE constexpr decltype(auto) size(const Container &cont) noexcept(noexcept(cont.size()))
获取容器的大小
MSTL_NODISCARD MSTL_ALWAYS_INLINE constexpr decltype(auto) cend(const Container &cont) noexcept(noexcept(cont.cend()))
获取const容器的const结束迭代器
MSTL_NODISCARD MSTL_ALWAYS_INLINE constexpr decltype(auto) begin(Container &cont) noexcept(noexcept(cont.begin()))
获取容器的起始迭代器
MSTL_NODISCARD MSTL_ALWAYS_INLINE constexpr decltype(auto) cbegin(const Container &cont) noexcept(noexcept(cont.cbegin()))
获取const容器的const起始迭代器