std::experi...ation::line(3)
π std::experi...ation::line(3) β C++ Standard Library, bestie edition β¨
okay so picture this: you're flipping through the <experimental/source_location> section of the C++ Standard Library manual (page std::experi...ation::line(3), yes the header truncated it, she's shy) and you land on this little icon. Let me explain her to you π«Ά
β¨ NAME β¨
std::experimental::source_location::line β yes bestie, that's the whole name, twice, that's just how the manual page rolls π
πΈ Synopsis πΈ
constexpr std::uint_least32_t line() const noexcept; (library fundamentals TS v2)
Returns the line number represented by this object.
That's it. That's the vibe. One function, zero drama, constexpr and noexcept because she's that girl π
π Parameters π
(none)
Literally nothing. No arguments. Empty set. She takes nothing from you and gives you a line number. main character energy fr fr π
π¦ Return value π¦
The line number represented by this object. π
β Example β
okay this example ate, no cap. Run this code:
// Run this code
#include <experimental/source_location>
#include <iostream>
#include <string_view>
using std::experimental::source_location;
inline void cur_line(
const std::string_view message = "",
const source_location& location = source_location::current())
{
std::cout
<< location.line() // <- the call-site line #
<< ") "
<< message;
}
int main()
{
cur_line("++" "\n");
cur_line(); std::cout << "Hello," "\n";
cur_line(); std::cout << "C++20!" "\n";
cur_line("--" "\n");
}
π₯ Output π₯
18) ++
19) Hello,
20) C++20!
21) --
like, the way it just knows what line it got called from?? the default argument source_location::current() is doing all the heavy lifting and she makes it look effortless πβ¨
π 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)- C++ documentation for Filename and line information
and that's the whole page, bestie π
source / version / date energy for the sign-off: brought to you by http://cppreference.com, dated 2024.06.10, on manual page std::experi...ation::line(3). go forth and call location.line() responsibly π§π
π¦ 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