std::source_location::line - cppreference.com (original) (raw)
Returns the line number represented by this object.
[edit] Parameters
(none)
[edit] Return value
The line number represented by this object.
An implementation is encouraged to return 0 when the line number is unknown.
[edit] Example
#include #include #include inline void cur_line( const std::string_view message = "", const std::source_location& location = std::source_location::current()) { std::cout << location.line() // <- the line # of a call site << ") " << message; } int main() { cur_line("++\n"); cur_line(); std::cout << "Hello,\n"; cur_line(); std::cout << "C++20!\n"; cur_line("--\n"); }
Output:
- ++
- Hello,
- C++20!
- --
[edit] See also
| | return the column number represented by this object (public member function) [edit] | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | | return the file name represented by this object (public member function) [edit] | | | return the name of the function represented by this object, if any (public member function) [edit] | | | gets the line number that lexically relates the evaluation represented by the stacktrace_entry (public member function of std::stacktrace_entry) [edit] | | Filename and line information |