std::source...n::file_name(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– NAME πŸ’–

std::source_location::file_name - std::source_location::file_name

okay so bestie, welcome to the std::source...n::file_name(3) page from the C++ Standard Libary manual β€” yes, the manual name literally says Libary, and I’m not fixing it, that’s canon πŸ˜­πŸ’…. This whole page is about std::source_location::file_name, and the NAME line is iconic in its redundancy: std::source_location::file_name - std::source_location::file_name. periodt.


πŸŽ€ Synopsis πŸŽ€

constexpr const char* file_name() const noexcept;  (since C++20)

so this function is constexpr, returns const char*, takes no args, is const, and is noexcept, and it’s been here (since C++20), no cap. It returns the name of the current source file represented by this object, represented as a null-terminated byte string. that’s the vibe. ✨


🫢 Parameters 🫢

(none) β€” literally no parameters, bestie. not even one. 🫢


🌸 Return value 🌸

The name of the current source file represented by this object, represented as a null-terminated byte string. that’s the whole return value, and it ate. πŸ’–


πŸ¦‹ Example πŸ¦‹

here’s the example, run it if you want:

// Run this code

#include <iostream>
#include <source_location>

void print_this_file_name(
    std::source_location location = std::source_location::current())
{
    // Name of file that contains the call site of this function.
    std::cout << "File: " << location.file_name() << '\n';
}

int main()
{
#line 1 "cppreference.cpp"
    print_this_file_name();
}

🌈 Output 🌈

the output is giving:

File: cppreference.cpp

πŸ‘‘ See also πŸ‘‘

the see-also squad is right here, bestie:

  • line β€” return the line number represented by this object (public member function).
  • column β€” return the column number represented by this object (public member function).
  • function_name β€” return the name of the function represented by this object, if any (public member function).
  • source_file (C++23) β€” gets the name of the source file that lexically contains the expression or statement whose evaluation is represented by the stacktrace_entry (public member function of std::stacktrace_entry).
  • Filename and line information β€” also in the see-also list, and we’re including it because every detail stays, periodt. 🫢

xoxo πŸ’‹ β€” sourced from http://cppreference.com, version/date 2024.06.10, and filed under std::source...n::file_name(3). bye bestie, go get that file name! πŸŒˆπŸ‘‘

πŸ“¦ where this page comes from