std::experi...ation::line(3)

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

πŸ’… 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