std::source_location:: current
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||
| Creation | ||||
|
source_location::current
|
||||
| Field access | ||||
|
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 <source_location> #include <iostream> struct src_rec { std::source_location srcl = std::source_location::current(); int dummy = 0; src_rec(std::source_location loc = std::source_location::current()) : srcl(loc) // 멤버 값들은 호출 함수의 위치를 참조합니다 {} src_rec(int i) : // 멤버 값들은 이 위치를 참조합니다 dummy(i) {} src_rec(double) // 멤버 값들은 이 위치를 참조합니다 {} }; std::source_location src_clone(std::source_location a = std::source_location::current()) { return a; } std::source_location src_make() { std::source_location b = std::source_location::current(); return b; } int main() { src_rec srec0; src_rec srec1(0); src_rec srec2(0.0); auto s0 = std::source_location::current(); auto s1 = src_clone(s0); auto s2 = src_clone(); auto s3 = src_make(); std::cout << srec0.srcl.line() << ' ' << srec0.srcl.function_name() << '\n' << srec1.srcl.line() << ' ' << srec1.srcl.function_name() << '\n' << srec2.srcl.line() << ' ' << srec2.srcl.function_name() << '\n' << s0.line() << ' ' << s0.function_name() << '\n' << s1.line() << ' ' << s1.function_name() << '\n' << s2.line() << ' ' << s2.function_name() << '\n' << s3.line() << ' ' << s3.function_name() << '\n'; }
가능한 출력:
31 int main() 12 src_rec::src_rec(int) 15 src_rec::src_rec(double) 34 int main() 34 int main() 36 int main() 25 std::source_location src_make()
참고 항목
구현 정의 값으로 새로운
source_location
을 생성함
(public 멤버 함수) |
|
|
[static]
|
현재 스택 트레이스 또는 주어진 부분을 획득함
(
std::basic_stacktrace<Allocator>
의 public static 멤버 함수)
|