Skip to content

Commit ea4039e

Browse files
authored
Update 003_stacktrace_stacktrace_entry.cpp
1 parent 7ad0033 commit ea4039e

1 file changed

Lines changed: 52 additions & 1 deletion

File tree

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,52 @@
1-
1
1+
#include <iostream>
2+
#include <string_view>
3+
#include <source_location>
4+
5+
void log(const std::string_view message,
6+
const std::source_location location =
7+
std::source_location::current())
8+
{
9+
std::cout << "file: "
10+
<< location.file_name() << "("
11+
<< location.line() << ":"
12+
<< location.column() << ") `"
13+
<< location.function_name() << "`: "
14+
<< message << '\n';
15+
}
16+
17+
template <typename T> void fun(T x)
18+
{
19+
log(x);
20+
}
21+
22+
int main(int, char*[])
23+
{
24+
log("Hello world!");
25+
fun("Hello C++20!");
26+
}
27+
#include <iostream>
28+
#include <string_view>
29+
#include <source_location>
30+
31+
void log(const std::string_view message,
32+
const std::source_location location =
33+
std::source_location::current())
34+
{
35+
std::cout << "file: "
36+
<< location.file_name() << "("
37+
<< location.line() << ":"
38+
<< location.column() << ") `"
39+
<< location.function_name() << "`: "
40+
<< message << '\n';
41+
}
42+
43+
template <typename T> void fun(T x)
44+
{
45+
log(x);
46+
}
47+
48+
int main(int, char*[])
49+
{
50+
log("Hello world!");
51+
fun("Hello C++20!");
52+
}

0 commit comments

Comments
 (0)