std::source_location:: function_name
From cppreference.net
<
cpp
|
utility
|
source location
C++
Utilities library
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::source_location
| Member functions | ||||
| Creation | ||||
| Field access | ||||
|
source_location::function_name
|
|
constexpr
const
char
*
function_name
(
)
const
noexcept
;
|
(seit C++20) | |
Gibt den Namen der Funktion zurück, der mit der durch dieses Objekt repräsentierten Position verknüpft ist, falls vorhanden.
Inhaltsverzeichnis |
Parameter
(keine)
Rückgabewert
Wenn dieses Objekt eine Position im Rumpf einer Funktion repräsentiert, gibt es einen implementierungsdefinierten nullterminierten Byte-String zurück, der dem Namen der Funktion entspricht.
Andernfalls wird eine leere Zeichenkette zurückgegeben.
Beispiel
std::source_location::function_name
kann dabei helfen, die Namen von Funktionen (einschließlich der speziellen Funktionen) zusammen mit ihren Signaturen zu erhalten.
Diesen Code ausführen
#include <cstdio> #include <utility> #include <source_location> inline void print_function_name( const std::source_location& location = std::source_location::current()) { std::puts(location.function_name()); // prints the name of the caller } void foo(double &&) { print_function_name(); } namespace bar { void baz() { print_function_name(); } } template <typename T> auto pub(T) { print_function_name(); return 42; } struct S { S() { print_function_name(); } S(int) { print_function_name(); } ~S() { print_function_name(); } S& operator=(S const&) { print_function_name(); return *this; } S& operator=(S&&) { print_function_name(); return *this; } }; int main(int, char const* const[]) { print_function_name(); foo(3.14); bar::baz(); pub(0xFULL); S p; S q{42}; p = q; p = std::move(q); [] { print_function_name(); }(); }
Mögliche Ausgabe:
int main(int, const char* const*) void foo(double&&) void bar::baz() auto pub(T) [with T = long long unsigned int] S::S() S::S(int) S& S::operator=(const S&) S& S::operator=(S&&) main(int, const char* const*)::<lambda()> S::~S() S::~S()
Siehe auch
|
gibt die Zeilennummer zurück, die von diesem Objekt repräsentiert wird
(öffentliche Elementfunktion) |
|
|
gibt die Spaltennummer zurück, die von diesem Objekt repräsentiert wird
(öffentliche Elementfunktion) |
|
|
gibt den Dateinamen zurück, der von diesem Objekt repräsentiert wird
(öffentliche Elementfunktion) |