static consteval source_location current() noexcept;
Element | Value |
line_ | A presumed line number ([cpp.predefined]). Line numbers are presumed to be 1-indexed; however, an implementation is encouraged to use 0 when the line number is unknown. |
column_ | An implementation-defined value denoting some offset from the start of the line denoted by line_. Column numbers are presumed to be 1-indexed; however, an implementation is encouraged to use 0 when the column number is unknown. |
file_name_ | A presumed name of the current source file ([cpp.predefined]) as an ntbs. |
function_name_ | A name of the current function such as in __func__ ([dcl.fct.def.general]) if any, an empty string otherwise. |
struct s { source_location member = source_location::current(); int other_member; s(source_location loc = source_location::current()) : member(loc) // values of member refer to the location of the calling function ([dcl.fct.default]) {} s(int blather) : // values of member refer to this location other_member(blather) {} s(double) // values of member refer to this location {} }; void f(source_location a = source_location::current()) { source_location b = source_location::current(); // values in b refer to this line } void g() { f(); // f's first argument corresponds to this line of code source_location c = source_location::current(); f(c); // f's first argument gets the same values as c, above }— end example
constexpr source_location() noexcept;