std::source_location Class
The <source_location> header provides a new class called std::source_location, which has the following member functions:
- file_name(): The function or expression’s defined source file name can be obtained in the form of a std::string object upon return.
- line(): An integer that is not signed, which includes the number of the source file line where the expression or function has been defined, is returned.
- column(): The function or expression’s defined column number in the source file is included in an unsigned int return value.
- function_name(): The std::source_location object’s origin function name is returned in a std::string object.
- current(): It is a static member function that is used to create a source location object of the place where it is called in the program.
Syntax
std::source_location src = source_location_objects;
std::source_location in C++ 20
The latest C++ standard version 20, brought about a fresh header file called <source_location> Header. It has an efficient method of obtaining details of a function or expression’s source location while running. This functionality is immensely beneficial for debugging and profiling activities that help developers locate errors and performance problems more quickly.