Skip to content

Commit 746c854

Browse files
author
Artiom N.
committed
Stacktrace example add
1 parent 3c2554e commit 746c854

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/book01/ch24/cpp/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
cmake_minimum_required(VERSION 3.10)
22

3+
4+
# add_subdirectory("stacktrace")
5+
36
if (UNIX)
47
add_subdirectory("signal_handling")
58
endif()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
3+
project("${CHAPTER_NAME}stacktrace" C CXX)
4+
5+
6+
set(CMAKE_CXX_STANDARD 23)
7+
add_executable("${PROJECT_NAME}" "main.cpp")
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <algorithm>
2+
#include <iostream>
3+
#include <stacktrace>
4+
5+
6+
int main()
7+
{
8+
auto trace = std::stacktrace::current();
9+
auto empty_trace = std::stacktrace{};
10+
11+
std::for_each(trace.begin(), trace.end(), [](const auto& f) { std::cout << f << '\n'; });
12+
13+
if (empty_trace.begin() == empty_trace.end()) std::cout << "stacktrace 'empty_trace' is indeed empty." << std::endl;
14+
}

0 commit comments

Comments
 (0)