Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::experimental::source_location

      From cppreference.com
      <cpp‎ |experimental
       
       
       
       
       
      Merged into ISO C++ The functionality described on this page was merged into the mainline ISO C++ standard as of 7/2019, seestd::source_location(since C++20)
      struct source_location;
      (library fundamentals TS v2)

      Thesource_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. Thesource_location class provides a better alternative.

      Contents

      [edit]Member functions

      Creation
      constructs a newsource_location with implementation-defined values
      (public member function)[edit]
      [static]
      constructs a newsource_location
      (public static member function)[edit]
      Other special member functions
      (destructor)
      (implicitly declared)
      destructs asource_location
      (public member function)[edit]
      operator=
      (implicitly declared)
      implicitly declared copy/move assignment operators
      (public member function)[edit]
      Field access
      return the line number represented by this object
      (public member function)[edit]
      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]

      [edit]Example

      Run this code
      #include <experimental/source_location>#include <iostream>#include <string_view> void log(conststd::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!
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/experimental/source_location&oldid=164578"

      [8]ページ先頭

      ©2009-2025 Movatter.jp