std::experimental::source_location:: function_name
From cppreference.net
<
cpp
|
experimental
|
source location
|
constexpr
const
char
*
function_name
(
)
const
noexcept
;
|
(ライブラリファンダメンタルTS v2) | |
このオブジェクトが表す位置に関連付けられた関数の名前があれば、それを返します。
目次 |
パラメータ
(なし)
戻り値
このオブジェクトが関数本体の位置を表す場合、その関数名に対応する実装定義のヌル終端バイト文字列を返します。
それ以外の場合、空の文字列が返されます。
例
以下の例は、
std::source_location::function_name()
を使用して、関数、コンストラクタ、デストラクタ、またはオーバーロードされた
operator()
の名前を出力する方法を示しています。
このコードを実行
#include <experimental/source_location> #include <iostream> #include <string_view> inline void function_name( const std::string_view signature = "()", const std::experimental::source_location& location = std::experimental::source_location::current()) { std::cout << location.function_name() // <- 呼び出し元の名前! << signature << '\n'; } void foo() { function_name(); } struct S { S() { function_name(); } S(int) { function_name("(int)"); } S& operator=(S const&) { function_name("(const S&)"); return *this; } S& operator=(S&&) { function_name("(S&&)"); return *this; } ~S() { function_name(); } }; int main() { foo(); S p; S q{42}; p = q; p = std::move(q); }
出力例:
foo() S() S(int) operator=(const S&) operator=(S&&) ~S() ~S()
関連項目
|
このオブジェクトが表す行番号を返す
(public member function) |
|
|
このオブジェクトが表すカラム番号を返す
(public member function) |
|
|
このオブジェクトが表すファイル名を返す
(public member function) |
|
|
C++ documentation
for
ファイル名と行情報
|
|