Skip to content

Commit

Permalink
Fixed an issue with the string insertion operator not being able to u…
Browse files Browse the repository at this point in the history
…se stream insertion operators declared after its own code.
  • Loading branch information
PazerOP committed Mar 20, 2020
1 parent 1e891c6 commit 00e9661
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions cpp/include/mh/text/string_insertion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,35 @@ namespace mh
};

using strwrapperstream = basic_strwrapperstream<>;

namespace detail
{
template<typename T>
struct make_dependent
{
using type = T;
};

// Force dependent typename for T, so we can use stream insertion operators declared after ourselves
template<typename T, typename CharT, typename Traits, typename Alloc>
inline void insertion_op_impl(std::basic_string<CharT, Traits, Alloc>& str, const typename make_dependent<T>::type& value)
{
mh::basic_strwrapperstream<CharT, Traits, Alloc> stream(str);
stream << value;
}
}
}

template<typename T, typename CharT = char, typename Traits = std::char_traits<CharT>, typename Alloc = std::allocator<CharT>>
inline std::string& operator<<(std::basic_string<CharT, Traits, Alloc>& str, const T& value)
{
mh::basic_strwrapperstream<CharT, Traits, Alloc> stream(str);
stream << value;
mh::detail::insertion_op_impl<T, CharT, Traits, Alloc>(str, value);
return str;
}

template<typename T, typename CharT = char, typename Traits = std::char_traits<CharT>, typename Alloc = std::allocator<CharT>>
inline std::string operator<<(std::basic_string<CharT, Traits, Alloc>&& str, const T& value)
{
mh::basic_strwrapperstream<CharT, Traits, Alloc> stream(str);
stream << value;
mh::detail::insertion_op_impl<T, CharT, Traits, Alloc>(str, value);
return std::move(str);
}

0 comments on commit 00e9661

Please sign in to comment.