名前空間
変種
操作

std::experimental::source_location::function_name

From cppreference.com
 
 
 
 
 
constexpr const char* function_name() const noexcept;
(Library Fundamentals 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() // <- name of the caller!
        << 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 メンバー関数) [編集]
このオブジェクトが表す列番号を返す
(public メンバー関数) [編集]
このオブジェクトが表すファイル名を返す
(public メンバー関数) [編集]
C++ ドキュメントファイル名と行情報
English 日本語 中文(简体) 中文(繁體)