Compile-time name extraction for functions, methods, and class data members.
#include <scl/utility/meta/symbol.h>Contents:
symbol_name<S>Retrieves the qualified string name of a symbol (global function, member function, or data member).
This utility provides a unified way to extract identifiers for various C++ entities passed as non-type template parameters.
#include <scl/utility/meta/symbol.h>template <auto S> constexpr std::string_view symbol_name() noexcept;&).&Class::Method) and
pointer-to-data-members (&Class::Field).#include <scl/utility/meta/symbol.h>
namespace sys {
void initialize() {}
struct Clock {
int ticks;
void reset() {}
};
}
// Global/Namespaced function
static_assert(scl::symbol_name<sys::initialize>() == "sys::initialize");
// Member function
static_assert(scl::symbol_name<&sys::Clock::reset>() == "sys::Clock::reset");
// Data member (Property)
static_assert(scl::symbol_name<&sys::Clock::ticks>() == "sys::Clock::ticks");
Implementation of serialization frameworks, automatic command-line argument mapping, or debuggers where the string name of a class field or function is required at compile-time.
symbol_short_name<S>Retrieves only the terminal identifier of the symbol S.
#include <scl/utility/meta/symbol.h>template <auto S> constexpr std::string_view symbol_short_name() noexcept;#include <scl/utility/meta/symbol.h>
struct Processor {
void execute() {}
};
int main() {
// Returns "execute" instead of "Processor::execute"
constexpr auto name = scl::symbol_short_name<&Processor::execute>();
}