std::experimental:: source_location
From cppreference.net
<
cpp
|
experimental
|
헤더 파일에 정의됨
<experimental/source_location>
|
||
|
struct
source_location
;
|
(라이브러리 펀더멘털 TS v2) | |
source_location
클래스는 파일 이름, 줄 번호, 함수 이름과 같은 소스 코드의 특정 정보를 나타냅니다. 이전에는 호출 지점에 대한 이러한 정보를 얻고자 하는 함수(로깅, 테스트 또는 디버깅 목적을 위해)가 매크로를 사용해야 했으며, 이로 인해
__LINE__
및
__FILE__
과 같은 미리 정의된 매크로들이 호출자 컨텍스트에서 확장되었습니다.
source_location
클래스는 이에 대한 더 나은 대안을 제공합니다.
목차 |
멤버 함수
생성 |
|
구현 정의 값으로 새로운
source_location
을 생성함
(public member function) |
|
|
[static]
|
새로운
source_location
을 생성함
(public static member function) |
기타 특수 멤버 함수 |
|
|
(소멸자)
(암시적으로 선언됨)
|
source_location
을 소멸시킴
(public member function) |
|
operator=
(암시적으로 선언됨)
|
암시적으로 선언된 복사/이동 할당 연산자
(public member function) |
필드 접근 |
|
|
이 객체가 나타내는 줄 번호를 반환함
(public member function) |
|
|
이 객체가 나타내는 열 번호를 반환함
(public member function) |
|
|
이 객체가 나타내는 파일 이름을 반환함
(public member function) |
|
|
이 객체가 나타내는 함수 이름을 반환함 (있는 경우)
(public member function) |
|
예제
이 코드 실행
#include <experimental/source_location> #include <iostream> #include <string_view> void log(const std::string_view message, const std::experimental::source_location location = std::experimental::source_location::current()) { std::cout << "info:" << location.file_name() << ':' << location.line() << ' ' << message << '\n'; } int main() { log("Hello world!"); }
가능한 출력:
info:main.cpp:15 Hello world!