最終更新日時(UTC):
が更新

履歴 編集

function
<meta>

std::meta::access_context::scope(C++26)

consteval info scope() const;

概要

アクセスコンテキストのスコープのリフレクションを返す。

戻り値

このアクセスコンテキストが関連付けられているスコープのリフレクションを返す。

access_context::current()で取得したコンテキストの場合、current()を呼び出した時点で囲んでいる関数や名前空間などのスコープが返される。

#include <meta>
#include <print>

class C {
public:
  static void inspect() {
    // current()はinspect()関数内で呼ばれたので、スコープはinspect()関数
    constexpr auto ctx = std::meta::access_context::current();
    std::println("inspect()のスコープ: {}",
                 std::meta::display_string_of(ctx.scope()));
  }
};

void free_function() {
  // current()はfree_function()内で呼ばれたので、スコープはfree_function()
  constexpr auto ctx = std::meta::access_context::current();
  std::println("free_function()のスコープ: {}",
               std::meta::display_string_of(ctx.scope()));
}

int main() {
  // current()はmain()内で呼ばれたので、スコープはmain()
  constexpr auto ctx = std::meta::access_context::current();
  std::println("main()のスコープ: {}",
               std::meta::display_string_of(ctx.scope()));

  C::inspect();
  free_function();
}

出力例

main()のスコープ: int main()
inspect()のスコープ: static void C::inspect()
free_function()のスコープ: void free_function()

バージョン

言語

  • C++26

処理系

参照