Compare commits

...

2 commits

Author SHA1 Message Date
Tom Englund
5ac060bfcf
signal: check for trivially copyable (#95)
use is_trivially_copyable instead because is_arithmetic_v exludes small
POD structs, enums, and certain trivially copyable types.

also add a if guard in emit if we have no listeners, no point emitting.
2025-12-19 16:12:51 +00:00
1c527b30fe
cli/logger: flush stdout after logging 2025-12-17 20:09:42 +00:00
2 changed files with 5 additions and 1 deletions

View file

@ -26,10 +26,13 @@ namespace Hyprutils {
template <typename... Args> template <typename... Args>
class CSignalT : public CSignalBase { class CSignalT : public CSignalBase {
template <typename T> template <typename T>
using RefArg = std::conditional_t<std::is_reference_v<T> || std::is_arithmetic_v<T>, T, const T&>; using RefArg = std::conditional_t<std::is_trivially_copyable_v<T>, T, const T&>;
public: public:
void emit(RefArg<Args>... args) { void emit(RefArg<Args>... args) {
if (m_vListeners.empty() && m_vStaticListeners.empty())
return;
if constexpr (sizeof...(Args) == 0) if constexpr (sizeof...(Args) == 0)
emitInternal(nullptr); emitInternal(nullptr);
else { else {

View file

@ -134,6 +134,7 @@ void CLoggerImpl::log(eLogLevel level, const std::string_view& msg, const std::s
if (m_stdoutEnabled) { if (m_stdoutEnabled) {
try { try {
std::println("{}{}", m_colorEnabled ? logPrefixColor : logPrefix, logMsg); std::println("{}{}", m_colorEnabled ? logPrefixColor : logPrefix, logMsg);
std::fflush(stdout);
} catch (std::exception& e) { } catch (std::exception& e) {
; // this could be e.g. stdout closed ; // this could be e.g. stdout closed
} }