cpp-common/bt2c: add format_as() template functions for wise enums
[babeltrace.git] / src / cpp-common / bt2c / fmt.hpp
index 8af3d71e49ca84f0205fb6f20e112ea84e5a5aed..4633ebca73b03233e1cc2c9ec7e9df120c66d463 100644 (file)
@@ -6,11 +6,27 @@
 
 #include "common/common.h"
 #include "cpp-common/bt2/message.hpp"
-#include "cpp-common/bt2c/uuid.hpp"
 #include "cpp-common/vendor/fmt/format.h" /* IWYU pragma: keep */
+#include "cpp-common/vendor/wise-enum/wise_enum.h"
+
+#include "uuid.hpp"
+
+namespace internal {
+
+template <typename T>
+using EnableIfIsWiseEnum =
+    typename std::enable_if<wise_enum::is_wise_enum<T>::value, const char *>::type;
+
+} /* namespace internal */
 
 namespace bt2 {
 
+template <typename T>
+::internal::EnableIfIsWiseEnum<T> format_as(const T val) noexcept
+{
+    return wise_enum::to_string<T>(val);
+}
+
 inline const char *format_as(const MessageType type)
 {
     return bt_common_message_type_string(static_cast<bt_message_type>(type));
@@ -20,6 +36,12 @@ inline const char *format_as(const MessageType type)
 
 namespace bt2c {
 
+template <typename T>
+::internal::EnableIfIsWiseEnum<T> format_as(const T val) noexcept
+{
+    return wise_enum::to_string<T>(val);
+}
+
 inline std::string format_as(const UuidView uuid)
 {
     return uuid.str();
This page took 0.024383 seconds and 4 git commands to generate.