GMP 0.3.0
Generative Metaprogramming library for C++
Loading...
Searching...
No Matches
type_name.hpp
Go to the documentation of this file.
1// ___ __ __ ___
2// / __| \/ | _ \ GMP(Generative Metaprogramming)
3// | (_ | |\/| | _/ version 0.3.0
4// \___|_| |_|_| https://github.com/lkimuk/gmp
5//
6// SPDX-FileCopyrightText: 2023-2026 Miles Li <https://www.cppmore.com/>
7// SPDX-License-Identifier: MIT
8//
9// This file is part of the GMP (Generative Metaprogramming) library.
10// Full project source: https://github.com/lkimuk/gmp
11
12#ifndef GMP_META_TYPE_NAME_HPP_
13#define GMP_META_TYPE_NAME_HPP_
14
15#include <array>
16#include <string>
17#include <vector>
18
19#include <gmp/meta/detail/name.hpp>
21
22namespace gmp {
23
52template<typename T>
53consteval auto type_name() {
54 constexpr auto name = detail::type_name_of<T>();
55#if GMP_COMPILER_MSVC
56 constexpr fixed_string<name.size()> type(name);
57 return remove_all<"class ", "struct ", "enum ">(constant_arg<type>);
58#else
59 return fixed_string<name.size()>(name);
60#endif
61}
62
63template<typename T>
78 consteval auto operator()() { return type_name<T>(); }
79};
80
81template<>
85struct pretty_type_name<std::string> {
91 consteval auto operator()() { return fixed_string("std::string"); }
92};
93
94template<>
98struct pretty_type_name<std::string_view> {
104 consteval auto operator()() { return fixed_string("std::string_view"); }
105};
106
107template<typename T>
113struct pretty_type_name<std::vector<T>> {
119 consteval auto operator()() {
120 return "std::vector<"_fs + pretty_type_name<T>()() + ">"_fs;
121 }
122};
123
124template<typename T, std::size_t N>
131struct pretty_type_name<std::array<T, N>> {
137 consteval auto operator()() {
138 return "std::array<"_fs + pretty_type_name<T>()() +
139 ", "_fs + to_fixed_string_v<N> + ">"_fs;
140 }
141};
142
145} // namespace gmp
146
147#endif // GMP_META_TYPE_NAME_HPP_
consteval auto remove_all(constant_arg_t< String >)
Remove all occurrences of one or more compile-time substrings.
consteval auto type_name()
Get the string representation of a type at compile-time.
Definition type_name.hpp:53
consteval auto enum_values()
Get all enumerator values of an enumeration type at compile-time.
Definition meta.hpp:155
Definition lock.hpp:21
A compile-time string type with fixed length and constexpr operations.
consteval size_type size() const noexcept
Capacity.
consteval auto operator()()
Get the formatted type name.
consteval auto operator()()
Get the formatted type name.
Definition type_name.hpp:91
consteval auto operator()()
Get the formatted type name.
consteval auto operator()()
Get the formatted type name.
Format a type name for documentation-friendly display.
Definition type_name.hpp:72
consteval auto operator()()
Get the formatted type name.
Definition type_name.hpp:78