5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_INFO_TYPE_NAME_STRING_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_INFO_TYPE_NAME_STRING_HPP_
14#include "arene/base/algorithm/copy.hpp"
15#include "arene/base/array/array.hpp"
16#include "arene/base/constraints/constraints.hpp"
17#include "arene/base/contracts/contract.hpp"
18#include "arene/base/iterator/next.hpp"
19#include "arene/base/stdlib_choice/cstddef.hpp"
20#include "arene/base/stdlib_choice/enable_if.hpp"
21#include "arene/base/stdlib_choice/ignore.hpp"
22#include "arene/base/stdlib_choice/is_void.hpp"
23#include "arene/base/string_algorithms.hpp"
24#include "arene/base/strings/inline_string.hpp"
25#include "arene/base/strings/string_view.hpp"
30namespace type_name_string_detail {
40constexpr auto get_big_raw_type_name_length_hint()
noexcept -> std::size_t {
41 return arene::base::string_length(
static_cast<
char const*>(
__PRETTY_FUNCTION__));
48template <std::nullptr_t =
nullptr>
49extern constexpr std::size_t void_length_hint = get_big_raw_type_name_length_hint<
void>();
54template <
typename T,
typename = constraints<>>
55extern constexpr std::size_t raw_type_name_buffer_size = 200;
65constexpr auto get_big_raw_type_name()
noexcept -> array<
char, raw_type_name_buffer_size<T>> {
66 array<
char, raw_type_name_buffer_size<T>> res{};
67 char const* name_str{
static_cast<
char const*>(
__PRETTY_FUNCTION__)};
68 auto const length = string_length(name_str);
69 std::ignore = copy(name_str, arene::base::next(name_str,
static_cast<std::ptrdiff_t>(length)), res.begin());
80extern constexpr auto big_raw_type_name = get_big_raw_type_name<T>();
85extern constexpr std::size_t raw_type_name_length = arene::base::string_length(big_raw_type_name<T>.data());
93extern constexpr std::size_t raw_type_name_buffer_size<T, constraints<std::enable_if_t<!std::is_void<T>::value>>> =
94 get_big_raw_type_name_length_hint<T>() - void_length_hint<> + raw_type_name_length<
void> + 1;
97 raw_type_name_buffer_size<
bool> == raw_type_name_length<
bool> + 1,
98 "The buffer for a non-void type must be just big enough for the name"
106constexpr auto get_raw_type_name_string_view()
noexcept -> string_view {
107 return {big_raw_type_name<T>.data(), raw_type_name_length<T>};
115 std::size_t characters_before;
117 std::size_t characters_after;
123inline constexpr auto get_name_offsets()
noexcept -> name_offsets {
124 constexpr string_view void_str{
"void"};
125 constexpr string_view void_name{get_raw_type_name_string_view<
void>()};
126 constexpr std::size_t pos{void_name.find(void_str)};
130 static_assert(pos < void_name.size(),
"'void' not found in function name");
132 return {pos, void_name.size() - (pos + void_str.size())};
137template <std::nullptr_t =
nullptr>
138extern constexpr name_offsets offsets = get_name_offsets();
151constexpr auto get_type_name_string_length()
noexcept -> std::size_t {
152 constexpr string_view full_name{get_raw_type_name_string_view<T>()};
153 ARENE_INVARIANT(offsets<>.characters_before < full_name.size());
154 ARENE_INVARIANT(offsets<>.characters_after < (full_name.size() - offsets<>.characters_before));
155 return full_name.size() - (offsets<>.characters_before + offsets<>.characters_after);
165extern constexpr std::size_t type_name_string_length = get_type_name_string_length<T>();
172constexpr auto get_type_name_string()
noexcept -> inline_string<type_name_string_length<T>> {
173 constexpr string_view full_name{get_raw_type_name_string_view<T>()};
174 ARENE_INVARIANT(offsets<>.characters_before < full_name.size());
175 ARENE_INVARIANT(type_name_string_length<T> < (full_name.size() - offsets<>.characters_before));
176 return inline_string<type_name_string_length<T>>{
177 full_name.substr(offsets<>.characters_before, type_name_string_length<T>)
Definition array_exceptions_disabled.cpp:11
constexpr auto type_name_v
The name of a type as an inline_string.
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10