fgerlits commented on code in PR #1589:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1589#discussion_r1259952982
##########
libminifi/include/core/Core.h:
##########
@@ -95,6 +98,62 @@ static inline std::string getClassName() {
#endif
}
+constexpr std::string_view removeStructOrClassPrefix(std::string_view input) {
+ constexpr std::string_view STRUCT = "struct "; // should be static
constexpr, but that is only allowed inside a constexpr function with std >=
c++23
+ constexpr std::string_view CLASS = "class ";
+
+ for (auto prefix : { STRUCT, CLASS }) {
+ if (input.find(prefix) == 0) {
+ return input.substr(prefix.size());
+ }
+ }
+ return input;
+}
+
+// based on
https://bitwizeshift.github.io/posts/2021/03/09/getting-an-unmangled-type-name-at-compile-time/
+template<typename T>
+constexpr auto typeNameArray() {
+#if defined(__clang__)
+ constexpr auto prefix = std::string_view{"[T = "};
+ constexpr auto suffix = std::string_view{"]"};
+ constexpr auto function = std::string_view{__PRETTY_FUNCTION__};
+#elif defined(__GNUC__)
+ constexpr auto prefix = std::string_view{"with T = "};
+ constexpr auto suffix = std::string_view{"]"};
+ constexpr auto function = std::string_view{__PRETTY_FUNCTION__};
+#elif defined(_MSC_VER)
+ constexpr auto prefix = std::string_view{"typeNameArray<"};
+ constexpr auto suffix = std::string_view{">(void)"};
+ constexpr auto function = std::string_view{__FUNCSIG__};
+#else
+# error Unsupported compiler
+#endif
+
+ static_assert(function.find(prefix) != std::string_view::npos &&
function.rfind(suffix) != std::string_view::npos);
+
+ constexpr auto start = function.find(prefix) + prefix.size();
+ constexpr auto end = function.rfind(suffix);
+ static_assert(start < end);
+
+#if defined(_MSC_VER)
+ constexpr auto name = removeStructOrClassPrefix(function.substr(start, end -
start));
+#else
+ constexpr auto name = function.substr(start, end - start);
+#endif
+
+ return utils::string_view_to_array<name.length()>(name);
+}
+
+template<typename T>
+struct TypeNameHolder {
+ static constexpr auto value = typeNameArray<T>();
+};
+
+template<typename T>
+constexpr std::string_view className() {
+ return utils::array_to_string_view(TypeNameHolder<T>::value);
+}
Review Comment:
added to the LICENSE and NOTICE files in
f93be28fc17ccafdf82f857fd6e2087453fbb3d4
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]