jeudi 13 juillet 2017

c++11 how to implement `std::string ToString(std::tuple

I want a very friendly ToString function for many types, include the std::tuple. The function is like this:

template <typename T>
inline std::string ToString(const T &t) { 
    std::stringstream ss;
    ss << t;
    return ss.str();
}

template <typename... Args>
inline std::string ToString(const std::tuple<Args...> &t) {
    std::stringstream ss;
    for (int i = 0; i < t.size(); i++) {
        ss << std::get<i>(t) << " ";
    }
    return ss.str();
}

The second part is wrong on grammar, how to implement it with c++11 template ?

Aucun commentaire:

Enregistrer un commentaire