In C and C++ you can get the name of the currently executing function through the __func__
macro with C99 & C++11 and ___FUNCTION___
for MSVC.
You can hack one together with std::any::type_name
.
macro_rules! function {
() => {{
fn f() {}
fn type_name_of(_: T) -> &'static str {
std::any::type_name::()
}
let name = type_name_of(f);
&name[..name.len() - 3]
}}
}
Note that this gives a full pathname, so my::path::my_func
instead of just my_func
. A demo is available.