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_
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"
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 = constra
ints<>>
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);
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>};
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>()};
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>()};
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>)
187extern constexpr auto type_name_v{type_name_string_detail::get_type_name_string<T>()};
#define ARENE_INVARIANT(condition)
Check that an invariant holds, and terminate the application if it does not.
Definition contract.hpp:161
Definition accumulate.hpp:37
ARENE_NODISCARD constexpr auto next(Iterator itr, typename std::iterator_traits< Iterator >::difference_type steps=1) noexcept(noexcept(::arene::base::advance(itr, steps))) -> Iterator
Produces the Nth successor (or predecessor if steps is negative) of an iterator.
Definition next.hpp:38
constexpr auto copy(InputIterator first, InputIterator last, OutputIterator output) noexcept(noexcept(*(++output)) &&noexcept(*(++first)) &&noexcept(first !=last) &&std::is_nothrow_assignable<, typename std::iterator_traits< InputIterator >::reference >::value) -> OutputIterator
Copies the elements in the range, defined by [first, last), to another range beginning at output.
Definition copy.hpp:40
constexpr auto type_name_v
The name of a type as an inline_string.
Definition accumulate.hpp:36
::ptrdiff_t ptrdiff_t
A type suitable for holding the difference between two pointers.
Definition cstddef.hpp:31
::size_t size_t
A type suitable for holding the size of an object.
Definition cstddef.hpp:29
static constexpr auto const & ignore
An object to which anything can be assigned, which ignores the assigned value.
Definition ignore.hpp:72
Public export header for the string_algorithms subpackage.