C++ Essence Library 0.1.0
A Utility Library for Modern C++ Programming
Loading...
Searching...
No Matches
friendly_name_base.hpp
1/*
2 * Copyright (c) 2024 The RefValue Project
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#pragma once
24
25#include "../basic_string.hpp"
26#include "../char8_t_remediation.hpp"
27#include "common_types.hpp"
28#include "identifier.hpp"
29#include "literal_string.hpp"
30
31#include <concepts>
32#include <cstddef>
33#include <cstdint>
34#include <span>
35#include <string_view>
36
37namespace essence::meta {
38 template <typename T, typename Tag = void>
40 static constexpr std::string_view value{friendly_name<T, original_name_cache_tag>::value};
41 };
42
43 template <typename T>
45 static constexpr auto origin = get_literal_string_t<T>();
46 static constexpr literal_string value{std::span<const char, origin.size()>{origin.data(), origin.size()}};
47 };
48
49 template <typename T, typename Tag = void>
50 inline constexpr auto friendly_name_v = friendly_name<T, Tag>::value;
51
52 template <>
53 struct friendly_name<std::int8_t> {
54 static constexpr std::string_view value{U8("int8")};
55 };
56
57 template <>
58 struct friendly_name<std::int16_t> {
59 static constexpr std::string_view value{U8("int16")};
60 };
61
62 template <>
63 struct friendly_name<std::int32_t> {
64 static constexpr std::string_view value{U8("int32")};
65 };
66
67 template <>
68 struct friendly_name<std::int64_t> {
69 static constexpr std::string_view value{U8("int64")};
70 };
71
72 template <>
73 struct friendly_name<std::uint8_t> {
74 static constexpr std::string_view value{U8("uint8")};
75 };
76
77 template <>
78 struct friendly_name<std::uint16_t> {
79 static constexpr std::string_view value{U8("uint16")};
80 };
81
82 template <>
83 struct friendly_name<std::uint32_t> {
84 static constexpr std::string_view value{U8("uint32")};
85 };
86
87 template <>
88 struct friendly_name<std::uint64_t> {
89 static constexpr std::string_view value{U8("uint64")};
90 };
91
92 template <>
93 struct friendly_name<float> {
94 static constexpr std::string_view value{U8("float")};
95 };
96
97 template <>
98 struct friendly_name<double> {
99 static constexpr std::string_view value{U8("double")};
100 };
101
102 template <>
103 struct friendly_name<long double> {
104 static constexpr std::string_view value{U8("long double")};
105 };
106
107 template <>
108 struct friendly_name<bool> {
109 static constexpr std::string_view value{U8("boolean")};
110 };
111
112 template <>
113 struct friendly_name<std::byte> {
114 static constexpr std::string_view value{U8("byte")};
115 };
116
117 template <>
118 struct friendly_name<char> {
119 static constexpr std::string_view value{U8("char")};
120 };
121
122 template <>
123 struct friendly_name<wchar_t> {
124 static constexpr std::string_view value{U8("wchar")};
125 };
126
127 template <>
128 struct friendly_name<char8_t> {
129 static constexpr std::string_view value{U8("u8char")};
130 };
131
132 template <>
133 struct friendly_name<char16_t> {
134 static constexpr std::string_view value{U8("u16char")};
135 };
136
137 template <>
138 struct friendly_name<char32_t> {
139 static constexpr std::string_view value{U8("u32char")};
140 };
141
142 template <std_basic_string T>
143 requires std::same_as<typename T::value_type, char>
144 struct friendly_name<T> {
145 static constexpr std::string_view value{U8("string")};
146 };
147
148 template <std_basic_string T>
149 requires std::same_as<typename T::value_type, wchar_t>
150 struct friendly_name<T> {
151 static constexpr std::string_view value{U8("wstring")};
152 };
153
154 template <std_basic_string T>
155 requires std::same_as<typename T::value_type, char8_t>
156 struct friendly_name<T> {
157 static constexpr std::string_view value{U8("u8string")};
158 };
159
160 template <std_basic_string T>
161 requires std::same_as<typename T::value_type, char16_t>
162 struct friendly_name<T> {
163 static constexpr std::string_view value{U8("u16string")};
164 };
165
166 template <std_basic_string T>
167 requires std::same_as<typename T::value_type, char32_t>
168 struct friendly_name<T> {
169 static constexpr std::string_view value{U8("u32string")};
170 };
171} // namespace essence::meta
Definition friendly_name_base.hpp:39
A literal type of collection of chars.
Definition literal_string.hpp:41
Definition common_types.hpp:72