1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| #include <iostream>
#include <string>
struct Logger
{
template<typename T>
Logger& operator << (const T& val)
{
std::cout << val << std::endl;
return *this;
}
};
template <typename T>
void log(Logger& l, T&& val)
{
l << std::forward<T>(val);
}
template <typename Head, typename... Tail>
void log(Logger& l, Head&& head, Tail&&... tail)
{
log(l << std::forward<Head>(head), std::forward<Tail>(tail)...);
}
int main()
{
int i = 0;
float f = 5.0f;
std::string s = "toto";
Logger l;
log(l, i, f, s, 1, 6.0, "titi");
} |
Partager