diff --git a/cpp/include/mh/text/string_insertion.hpp b/cpp/include/mh/text/string_insertion.hpp index 8940e24..f6d3f59 100644 --- a/cpp/include/mh/text/string_insertion.hpp +++ b/cpp/include/mh/text/string_insertion.hpp @@ -41,20 +41,35 @@ namespace mh }; using strwrapperstream = basic_strwrapperstream<>; + + namespace detail + { + template + struct make_dependent + { + using type = T; + }; + + // Force dependent typename for T, so we can use stream insertion operators declared after ourselves + template + inline void insertion_op_impl(std::basic_string& str, const typename make_dependent::type& value) + { + mh::basic_strwrapperstream stream(str); + stream << value; + } + } } template, typename Alloc = std::allocator> inline std::string& operator<<(std::basic_string& str, const T& value) { - mh::basic_strwrapperstream stream(str); - stream << value; + mh::detail::insertion_op_impl(str, value); return str; } template, typename Alloc = std::allocator> inline std::string operator<<(std::basic_string&& str, const T& value) { - mh::basic_strwrapperstream stream(str); - stream << value; + mh::detail::insertion_op_impl(str, value); return std::move(str); }