better print override
All checks were successful
Linux arm64 / Build (push) Successful in 15s

This commit is contained in:
2025-03-04 22:45:50 +01:00
parent 7f8d9e3f96
commit 77356ce749
6 changed files with 147 additions and 35 deletions

View File

@@ -0,0 +1,55 @@
#pragma once
#include <map>
#include <sp/common/Templates.h>
#include <string>
#include <vector>
namespace sp {
template <typename T, std::enable_if_t<details::is_general_t<T>::value, bool> = true>
inline std::string PrintData(const T& a_Data);
template <typename T, std::enable_if_t<details::is_primitive<T>::value, bool> = true>
inline std::string PrintData(T a_Data) {
return std::to_string(a_Data);
}
template <>
inline std::string PrintData(const std::string& a_Data) {
return "\"" + a_Data + "\"";
}
template <typename K, typename V>
std::string PrintData(const std::pair<K, V>& a_Data);
template <typename K, typename V>
std::string PrintData(const std::map<K, V>& a_Data);
template <typename T>
std::string PrintData(const std::vector<T>& a_Data);
template <typename K, typename V>
std::string PrintData(const std::pair<K, V>& a_Data) {
return "{" + PrintData(a_Data.first) + " => " + PrintData(a_Data.second) + "}";
}
template <typename K, typename V>
std::string PrintData(const std::map<K, V>& a_Data) {
std::string result = "{";
for (const auto& pair : a_Data) {
result += PrintData(pair) + ", ";
}
return result.substr(0, result.size() - 2) + "}";
}
template <typename T>
std::string PrintData(const std::vector<T>& a_Data) {
std::string result = "{";
for (const T& value : a_Data) {
result += PrintData(value) + ", ";
}
return result.substr(0, result.size() - 2) + "}";
}
} // namespace sp