perf: 在析构函数里调用 std::endl

This commit is contained in:
zzyyyl
2022-09-11 00:44:44 +08:00
parent a6c0fdb71a
commit ea65f206e6

View File

@@ -63,10 +63,6 @@ namespace asst
std::string_view str;
};
struct _endl
{};
static constexpr _endl endl {};
class LogStream
{
public:
@@ -76,6 +72,13 @@ namespace asst
{
(*this << ... << std::forward<Args>(buff));
}
~LogStream()
{
m_ofs << std::endl;
#ifdef ASST_DEBUG
std::cout << std::endl;
#endif
}
template <typename T>
LogStream& operator<<(T&& arg)
@@ -83,9 +86,6 @@ namespace asst
if constexpr (std::same_as<separator, std::decay_t<T>>) {
m_sep = std::forward<T>(arg);
}
else if constexpr (std::same_as<_endl, std::decay_t<T>>) {
m_ofs << std::endl;
}
else {
if (!m_is_first) {
#ifdef ASST_DEBUG
@@ -210,7 +210,7 @@ namespace asst
template <typename... Args>
inline void log(level lv, Args&&... args)
{
log(lv, std::forward<Args>(args)...);
((*this << lv) << ... << std::forward<Args>(args));
}
void flush()