std::source_location::line(3)
π std::source_location::line(3) π
okay bestie, welcome to the C++ Standard Libary page for std::source_location::line β manual name folded in near the top like a lilβ name tag, because weβre cute AND accurate π«Ά
πΈ NAME πΈ
std::source_location::line β std::source_location::line (iconic, no notes π
)
β¨ Synopsis β¨
Hereβs the signature, no cap:
constexpr std::uint_least32_t line() const noexcept; (since C++20)
Returns the line number represented by this object. Thatβs the whole vibe, fr fr.
π Parameters π
(none) β literally zero parameters, she takes no arguments and still serves π
π¦ Return value π¦
The line number represented by this object. β¨
An implementation is encouraged to return 0 when the line number is unknown. So if you see 0, thatβs the βidkβ answer β highkey useful to know, iykyk.
π» Example π»
Run this code π
// Run this code
#include <iostream>
#include <string_view>
#include <source_location>
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 π
17) ++
18) Hello,
19) C++20!
20) --
Ate, periodt. π
π See also π
columnβ return the column number represented by this object (public member function)file_nameβ return the file name 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_line(C++23) β gets the line number that lexically relates the evaluation represented by thestacktrace_entry(public member function ofstd::stacktrace_entry)- Filename and line information
kisses and compiler blessings π β from http://cppreference.com, dated 2024.06.10, for std::source_location::line(3) π§
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms