[ create a new paste ] login | about

Link: http://codepad.org/gLz0x6Vy    [ raw code | output | fork ]

C++, pasted on Jul 24:
template <typename T>
std::string toString(T const & t) {
    ostringstream out;
    out << t;
    return out.str();
}

template <>
std::string toString(char const* const & s) {
    cout << "(S1)";
    return std::string(s);
}

template <size_t N>
std::string toString(char (&s)[N]) {
    cout << "(S2)";
    return std::string(s);
}

template <size_t N>
std::string toString(char const (&s)[N]) {
    cout << "(S3)";
    return std::string(s);
}

int main() {
    const char* s1 = "Hi";
    cout << toString(s1) << endl;
    char s2[] = "There";
    cout << toString(s2) << endl;
    cout << toString(", Bob") << endl;
}


Output:
1
2
3
(S1)Hi
(S2)There
(S3), Bob


Create a new paste based on this one


Comments: