Allowed pointers to be logged/printed

This commit is contained in:
Pasha Bibko
2025-08-03 16:06:55 +01:00
parent 90a958a30b
commit 611c5012a7
3 changed files with 29 additions and 3 deletions

View File

@@ -156,7 +156,16 @@ namespace LXC::Util
requires Internal::HasLogStrFunc<T> || Internal::Logable<T>
inline void PrintLn(T&& arg)
{
if constexpr (Internal::HasLogStrFunc<T>)
if constexpr (std::is_pointer_v<T>)
{
if (arg != nullptr) _LIKELY
PrintLn(*arg);
else
Internal::WriteImpl<Util::Color::DEFAULT, true>(std::cout, "Nullptr to: [", typeid(std::remove_pointer_t<T>).name(), "]");
}
else if constexpr (Internal::HasLogStrFunc<T>)
Internal::WriteImpl<Util::Color::DEFAULT, true>(std::cout, arg.LogStr());
else
@@ -176,12 +185,21 @@ namespace LXC::Util
// Logs a singular argument to the log, calls Log() if it can on the object //
template<typename T>
requires Internal::HasLogStrFunc<T> || Internal::Logable<T>
inline void Log(T arg)
inline void Log(T&& arg)
{
std::ofstream& log = Internal::Log();
if (log.is_open()) _UNLIKELY
{
if constexpr (Internal::HasLogStrFunc<T>)
if constexpr (std::is_pointer_v<T>)
{
if (arg != nullptr) _LIKELY
Log(*arg);
else
Internal::WriteImpl<Util::Color::DEFAULT, true>(log, "[LXC] Nullptr to: [", typeid(std::remove_pointer_t<T>).name(), "]");
}
else if constexpr (Internal::HasLogStrFunc<T>)
Internal::WriteImpl<Util::Color::DEFAULT, true>(log, "[LXC] ", '{', arg.LogStr(), '}');
else