cppreference.com
Create account
Namespaces
Variants
Actions
 
 
 
Reflection library
 
Reflection types and queries
Reflection queries
Reflection layout queries
Type properties
Type property queries
 
Defined in header <meta>
consteval std::source_location source_location_of( std::meta::info r );
(since C++26)

Where possible, returns a source location of what r represents.

Formally:

  • if r represents a (scalar) value, a type other than class or enumeration type, the global namespace, or a data member description, returns a value-initialized std::source_location.
  • Otherwise, returns an implementation-defined value.

If r represents an entity with a definition that is reachable from the evaluation context, the implementation is encouraged to return a value corresponding to a definition.

Parameters

r - a reflection value

Return value

A source location of what r represents, as described above.

Example

#include <meta>
#include <iostream>
#include <source_location>

int main()
{
    std::cout << '#' << source_location_of(^^main).line()
              << ' ' << source_location_of(^^main).function_name()
              << '\n';
}

Possible output:

#5 int main()

See also

[static]
constructs a new source_location corresponding to the location of the call site
(public static member function of std::source_location)