38template <
class T>
consteval std::string_view
typeName();
39template <>
consteval std::string_view typeName<void>() {
return "void"; }
40template <>
consteval std::string_view typeName<int8_t>() {
return "int8_t"; }
41template <>
consteval std::string_view typeName<uint8_t>() {
return "uint8_t"; }
42template <>
consteval std::string_view typeName<int16_t>() {
return "int16_t"; }
43template <>
consteval std::string_view typeName<uint16_t>() {
return "uint16_t"; }
44template <>
consteval std::string_view typeName<int32_t>() {
return "int32_t"; }
45template <>
consteval std::string_view typeName<uint32_t>() {
return "uint32_t"; }
46template <>
consteval std::string_view typeName<int64_t>() {
return "int64_t"; }
47template <>
consteval std::string_view typeName<uint64_t>() {
return "uint64_t"; }
54consteval std::string_view typeNameWrappedInFunctionTemplateName()
59 return __PRETTY_FUNCTION__;
63template <
class R,
class Arg, R (*t) (Arg)>
64consteval std::string_view functionNameWrappedInFunctionTemplateName()
69 return __PRETTY_FUNCTION__;
73template <
class R,
class ArgA,
class ArgB, R (*t) (ArgA, ArgB)>
74consteval std::string_view functionNameWrappedInFunctionTemplateName()
79 return __PRETTY_FUNCTION__;
83consteval size_t wrappedTypeNamePrefixLength()
87 return typeNameWrappedInFunctionTemplateName<void>().find (typeName<void>());
90consteval size_t wrappedTypeNameSuffixLength()
92 return typeNameWrappedInFunctionTemplateName<void>().length() - wrappedTypeNamePrefixLength() - typeName<void>().length();
100 constexpr auto wrappedName = detail::typeNameWrappedInFunctionTemplateName<T>();
101 constexpr auto prefixLength = detail::wrappedTypeNamePrefixLength();
102 constexpr auto suffixLength = detail::wrappedTypeNameSuffixLength();
103 constexpr auto typeNameLength = wrappedName.length() - prefixLength - suffixLength;
105 return wrappedName.substr (prefixLength, typeNameLength);
109consteval std::string_view
typeName (
const T&)
111 return typeName<T>();
115template <
class R,
class Arg, R (*fn) (Arg)>
118 constexpr auto wrappedName = detail::functionNameWrappedInFunctionTemplateName<R, Arg, fn>();
120 constexpr auto prefixLen = wrappedName.find (
"functionNameWrappedInFunctionTemplateName<") + 42;
121 constexpr auto postfixLen = wrappedName.rfind (
">(void)");
122 constexpr auto onlyTemplateArgs = wrappedName.substr (prefixLen, postfixLen - prefixLen);
124 constexpr auto returnTypeName = typeName<R>();
125 constexpr auto returnTypeLen = onlyTemplateArgs.find (returnTypeName) + returnTypeName.size() + 1;
126 constexpr auto onlyTemplateArgsNoReturnType = onlyTemplateArgs.substr (returnTypeLen);
128 constexpr auto argTypeName = typeName<Arg>();
129 constexpr auto argTypeLen = onlyTemplateArgsNoReturnType.find (argTypeName) + argTypeName.size() + 1;
130 constexpr auto onlyFunctionSignature = onlyTemplateArgsNoReturnType.substr (argTypeLen);
132 constexpr auto argPos = onlyFunctionSignature.find (
"(");
133 constexpr auto functionNameLen = argPos - returnTypeLen;
135 return onlyFunctionSignature.substr (returnTypeLen, functionNameLen);
137 constexpr auto prefixLength = wrappedName.find (
"&") + 1;
138 constexpr auto postfixPos = wrappedName.rfind (
"]");
139 constexpr auto functionNameLength = postfixPos - prefixLength;
140 return wrappedName.substr (prefixLength, functionNameLength);
145template <
class R,
class ArgA,
class ArgB, R (*fn) (ArgA, ArgB)>
148 constexpr auto wrappedName = detail::functionNameWrappedInFunctionTemplateName<R, ArgA, ArgB, fn>();
151 constexpr auto prefixLen = wrappedName.find (
"functionNameWrappedInFunctionTemplateName<") + 42;
152 constexpr auto postfixLen = wrappedName.rfind (
">(void)");
153 constexpr auto onlyTemplateArgs = wrappedName.substr (prefixLen, postfixLen - prefixLen);
155 constexpr auto returnTypeName = typeName<R>();
156 constexpr auto returnTypeLen = onlyTemplateArgs.find (returnTypeName) + returnTypeName.size() + 1;
157 constexpr auto onlyTemplateArgsNoReturnType = onlyTemplateArgs.substr (returnTypeLen);
159 constexpr auto argATypeName = typeName<ArgA>();
160 constexpr auto argATypeLen = onlyTemplateArgsNoReturnType.find (argATypeName) + argATypeName.size() + 1;
161 constexpr auto onlyTemplateArgsNoArgA = onlyTemplateArgsNoReturnType.substr (argATypeLen);
163 constexpr auto argBTypeName = typeName<ArgB>();
164 constexpr auto argBTypeLen = onlyTemplateArgsNoReturnType.find (argBTypeName) + argBTypeName.size() + 1;
165 constexpr auto onlyFunctionSignature = onlyTemplateArgsNoReturnType.substr (argBTypeLen);
167 constexpr auto argPos = onlyFunctionSignature.find (
"(");
168 constexpr auto functionNameLen = argPos - returnTypeLen;
170 return onlyFunctionSignature.substr (returnTypeLen, functionNameLen);
172 constexpr auto prefixLength = wrappedName.find (
"&") + 1;
173 constexpr auto postfixPos = wrappedName.rfind (
"]");
174 constexpr auto functionNameLength = postfixPos - prefixLength;
175 return wrappedName.substr (prefixLength, functionNameLength);
The main namespace of the VCTR project.
Definition: Array.h:24
consteval std::string_view functionName()
Returns the name for a function with a single argument.
Definition: template_arg_string_conversion.h:116
consteval std::string_view typeName()
Returns a string containing the templates type name.
Definition: template_arg_string_conversion.h:98