diff --git a/include/rfl.hpp b/include/rfl.hpp index 432fff2f6..ab48b0509 100644 --- a/include/rfl.hpp +++ b/include/rfl.hpp @@ -92,6 +92,7 @@ #include "rfl/to_named_tuple.hpp" #include "rfl/to_view.hpp" #include "rfl/tuple_cat.hpp" +#include "rfl/type_name.hpp" #include "rfl/type_name_t.hpp" #include "rfl/view_t.hpp" #include "rfl/visit.hpp" diff --git a/include/rfl/type_name.hpp b/include/rfl/type_name.hpp new file mode 100644 index 000000000..b5f594cae --- /dev/null +++ b/include/rfl/type_name.hpp @@ -0,0 +1,27 @@ +#ifndef RFL_TYPE_NAME_HPP_ +#define RFL_TYPE_NAME_HPP_ + +#include + +#include "internal/get_type_name.hpp" + +namespace rfl { + +/// Compile-time `std::string_view` containing the name of type `T` without +/// instantiating an `rfl::Literal` or `rfl::internal::StringLiteral`. +/// @tparam T The type whose name to retrieve +template +inline constexpr std::string_view type_name_v = + internal::get_type_name_str_view(); + +/// Returns the compile-time name of type `T` as a `std::string_view` (usable +/// in both `constexpr` and runtime contexts). +/// @tparam T The type whose name to retrieve +template +constexpr std::string_view type_name() noexcept { + return type_name_v; +} + +} // namespace rfl + +#endif