I'm trying to log some things on my cpp app. I chose to go on variadic parameters.
My log functions :
inline void log() {}
template<class... Args>
inline void log(std::string_view first, const Args&... args)
{
std::cout << first << std::endl;
log(args...);
}
To test, I'm trying to log this message :
for (int i = 0; i < 10; ++i) {
log("I am a message to log ... ", "123456789" + i);
}
I'm having this unexpected result (it should be the same number for each log message, no ?) :
I am a message to log ...
123456789
I am a message to log ...
23456789
I am a message to log ...
3456789
I am a message to log ...
456789
I am a message to log ...
56789
I am a message to log ...
6789
I am a message to log ...
789
I am a message to log ...
89
I am a message to log ...
9
I am a message to log ...
I think I'm missing something, somewhere in my code... I tried to run this code on 2 os (windows & linux mint), just to be sure x) !
Well, I'm stuck on this subject ...
Any ideas ? Thanks in advance !!!
"123456789" + iwould be "the same", regardless of the value ofi. Why perform this addition if you think it would have no effect?"123456789"is, and arithmetic on that type does.template <class First, class... Args> inline void log(First&& first, const Args&... args)you could log like this:log("I am a message to log ... ", "123456789", i);example