struct source_location;
(library fundamentals TS v2)The source_location
class represents certain information about the source code, such as file names, line numbers, and function names. Previously, functions that desire to obtain this information about the call site (for logging, testing, or debugging purposes) must use macros so that predefined macros like __LINE__ and __FILE__ are expanded in the context of the caller. The source_location
class provides a better alternative.
source_location
with implementation-defined values
source_location
(destructor)
(implicitly declared)
destructs asource_location
operator=
(implicitly declared)
implicitly declared copy/move assignment operators#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!"); }
Possible output:
info:main.cpp:15 Hello world!
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4