Это валидный код или же предупреждение по делу и так нельзя?:
| Скрытый текст |
| template<unsigned int N_LIMIT, class TLogData>
void LogErr(std::string strLog)
{
static std::atomic<unsigned int> nCounter{};
if ( nCounter <= N_LIMIT )
{
if ( nCounter == N_LIMIT )
{
strLog += " The message limit exceeded. The logging of this message has been stopped.";
}
const TLogData logData{};
std::cout() << strLog << " file: \"" << logData._file << "\" fun: \"" << logData._func << '"' << std::endl;
++nCounter;
}
}
|
| |
std::string Asdf() noexcept
try
{
throw 1;
return "ASDF";
}
catch(...)
{
struct LogData
{
const std::string_view _file = __FILE__;
const unsigned int _line = __LINE__;
const std::string_view _func = __func__; // warning: predefined identifier is only valid inside function
};
LogErr<100, LogData>("Test.");
return {};
}
вроде работает...