mardi 5 mai 2015

c++11 variadic templates recursive

I am trying to understand how recursive variadic templates works.

#include <iostream>

template<typename T>
static inline void WriteLog(T&& msg) {
    std::wcout << std::forward<T>(msg);
}

template<typename T, typename... Ts>
static void WriteLog(T&& msg, Ts&&... Vals) {
    WriteLog(std::forward<T>(msg));
    WriteLog(std::forward<Ts>(Vals)...);
    std::wcout << "\n**End**";
}

int main() {
    WriteLog("apple, ", "orange, ", "mango");
}

OutPut:

apple, orange, mango
**End**
**End**

I expect only one **End**. Why its printed twice?

Aucun commentaire:

Enregistrer un commentaire