FreeBSD Manual Pages
std::experi...ce_location(3) C++ Standard Libary std::experi...ce_location(3) NAME std::experimental::source_location - std::experimental::source_location Synopsis Defined in header <experimental/source_location> struct source_location; (library fundamen- tals TS v2) The source_location class represents certain information about the source code, such as file names, line numbers, and function names. Previously, func- tions that desire to obtain this information about the call site (for logging, test- ing, 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. Member functions Creation constructs a new source_location with imple- mentation-defined constructor values (public member function) current constructs a new source_location [static] (public static member function) Other special member functions destructor destructs a source_location (implicitly declared) (public member function) operator= Implicitly declared copy/move assignment oper- ators (implicitly declared) (public member function) Field access line return the line number represented by this ob- ject (public member function) column return the column number represented by this object (public member function) file_name return the file name represented by this ob- ject (public member function) return the name of the function represented by this object, if function_name any (public member function) Example // Run this code #include <iostream> #include <string_view> #include <experimental/source_location> void log(const std::string_view& message, const std::experimen- tal::source_location& location = std::experimental::source_loca- tion::current()) { std::cout << "info:" << location.file_name() << ":" << location.line() << " " << message << '\n'; } int main() { log("Hello world!"); } Possible output: info:main.cpp:15 Hello world! http://cppreference.com 2022.07.31 std::experi...ce_location(3)
NAME | Synopsis | Member functions | Example | Possible output:
Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=std::experimental::source_location&sektion=3&manpath=FreeBSD+Ports+15.0>
