std::source_location::current
static consteval source_location current() noexcept;
|
(C++20부터) | |
호출 지점의 위치에 해당하는 새 source_location 객체를 생성합니다.
반환값
만약
current()
가 직접 호출되면(함수 호출에서
current()
를 명시적으로 지정하는 경우), 이는 호출 위치를 나타내는 구현 정의 값들을 가진
source_location
객체를 반환합니다. 이 값들은
#line
전처리기 지시문
의 영향을 미리 정의된 매크로
__LINE__
와
__FILE__
과 동일한 방식으로 받아야 합니다.
만약
current()
가
기본 멤버 초기화
에서 사용되면, 반환값은 데이터 멤버를 초기화하는 생성자 정의 또는
집합체 초기화
의 위치에 해당합니다.
만약
current()
가 기본 인자에서 사용되면, 반환 값은 호출 지점에서
current()
호출의 위치에 해당합니다.
만약
current()
가 다른 방식으로 호출되면, 반환 값은 지정되지 않습니다.
참고 사항
std::source_location::current
는 일반적으로 컴파일러의 내장 구현이 필요합니다.
예제
#include <print>
#include <source_location>
struct src_rec
{
std::source_location srcl = std::source_location::current();
int dummy{};
src_rec(std::source_location loc = std::source_location::current()) :
srcl(loc) // values of member refer to the location of the calling function
{}
src_rec(int i) : // values of member refer to this location
dummy(i)
{}
src_rec(double) // values of member refer to this location
{}
};
std::source_location src_clone(std::source_location a = std::source_location::current())
{
return a;
}
std::source_location src_make()
{
return std::source_location::current();
}
int main()
{
const auto r0 = src_rec();
const auto r1 = src_rec(0);
const auto r2 = src_rec(0.0);
const auto s0 = std::source_location::current();
const auto s1 = src_clone(s0);
const auto s2 = src_clone();
const auto s3 = src_make();
std::println("#{1} {0} {2}", "r0", r0.srcl.line(), r0.srcl.function_name());
std::println("#{1} {0} {2}", "r1", r1.srcl.line(), r1.srcl.function_name());
std::println("#{1} {0} {2}", "r2", r2.srcl.line(), r2.srcl.function_name());
std::println("#{1} {0} {2}", "s0", s0.line(), s0.function_name());
std::println("#{1} {0} {2}", "s1", s1.line(), s1.function_name());
std::println("#{1} {0} {2}", "s2", s2.line(), s2.function_name());
std::println("#{1} {0} {2}", "s3", s3.line(), s3.function_name());
}
가능한 출력:
#31 r0 int main()
#13 r1 src_rec::src_rec(int)
#16 r2 src_rec::src_rec(double)
#34 s0 int main()
#34 s1 int main()
#36 s2 int main()
#26 s3 std::source_location src_make()
참고 항목
구현 정의 값으로 새로운
source_location
을 생성함
(public 멤버 함수) |
|
|
[static]
|
현재 스택 트레이스 또는 주어진 부분을 획득함
(
std::basic_stacktrace<Allocator>
의 public static 멤버 함수)
|