template <typename T> buffer_t &operator<<(buffer_t &buffer, T data);
is the main template. Specializations are not primary templates. The compiler finds only primary templates when the matching functions, and then, if the selected template function has specializations, they look at them, if the compiler search specialization exactly matches the parameters - it uses them, and the other uses the primary template.
template <> buffer_t &operator<<(buffer_t &buffer, const Glib::ustring &data)
this specialization does not exactly match buffer_t << Glib::ustring("s") , but it exactly matches
template <> buffer_t &operator<<(buffer_t &buffer, Glib::ustring data)
I suggest you not use a specialized template function, use overloading.
template <typename T> buffer_t &operator<<(buffer_t &buffer, T data); buffer_t &operator<<(buffer_t &buffer, const char *data); buffer_t &operator<<(buffer_t &buffer, const Glib::ustring &data);
source share