std::experi..._source_line(3)
π std::experimental::reflect::get_source_line
okay bestie so this one lives in the C++ Standard Libary (yes that's the cppreference spelling, we don't gatekeep typos around here π«Ά) and it's a reflection TS situation. Buckle up, it's actually so cute and simple.
β¨ NAME β¨
std::experimental::reflect::get_source_line β and yeah, it's literally that, twice, because the name is the whole personality. It tells you what line a thing was declared on. That's it. That's the vibe. π
πΈ SYNOPSIS πΈ
Defined in header <experimental/reflect>:
template< Object T > (reflection TS)
struct get_source_line;
So it's a struct template over Object T, and it gives you a member constant value that's equal to the presumed line number of the declaration of the entity or typedef-name reflected by T. Obsessed. π₯
π MEMBER CONSTANTS π
valueβ the presumed line number of the declaration of the entity or typedef-name reflected byT. It's[static], and it's a public static member constant. Iconic behavior, no notes. β¨
π¦ MEMBER FUNCTIONS π¦
operator std::uint_least32_tβ converts the object tostd::uint_least32_t, and returnsvalue. Public member function, doing its little conversion thing. πoperator()(C++14)β returnsvalue. Public member function. That's it, she's lowkey just handing you the number. π«Ά
π MEMBER TYPES π
value_typeβ defined asstd::uint_least32_ttypeβ defined asstd::integral_constant<std::uint_least32_t, value>
(the original lays these out in a little table with columns Type / Definition β same facts, cuter packaging π)
π EXAMPLE π
The following code shows the source code line of an object or a class. Run this code, bestie:
#include<experimental/reflect>
#include<iostream>
using refl = std::experimental::reflect;
float f;
struct P{};
int main()
{
std::cout << refl::get_source_line_v<reflexpr(f)> << '\n';
std::cout << refl::get_source_line_v<reflexpr(P)> << '\n';
}
π Output
6
7
See, f is on line 6 and P is on line 7 β counting from the top of the file, #include lines included. The way it just knows?? Not me being emotionally attached to a compile-time constant. π
β SEE ALSO β
lineβ return the line number represented by this object (public member function ofstd::source_location)source_line(C++23)β gets the line number that lexically relates the evaluation represented by thestacktrace_entry(public member function ofstd::stacktrace_entry)
like, they're cousins. same energy, different standards. iykyk π
ngl, this is a tiny little reflection utility β no warnings, no deprecated anything, no bugs to report. just a struct that knows where stuff lives. main character energy fr fr π§
source: http://cppreference.com Β· version 2024.06.10 Β· the manual page formally known as std::experi..._source_line(3) β mwah, that's the sign-off, hope this slayed for you bestie π
πβ¨
π¦ 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