diff --git a/include/cppcore/conversion/string.h b/include/cppcore/conversion/string.h index fc6b380..5c051f3 100644 --- a/include/cppcore/conversion/string.h +++ b/include/cppcore/conversion/string.h @@ -218,6 +218,15 @@ namespace std std::forward(x).to_string(std::declval&>()), std::declval&>()); + /** + * @brief Operator overload to write value to stream that supports the to_string method, with stream parameter. + */ + template + inline auto operator<<(basic_ostream& os, X&& x) + -> decltype( + std::forward(x).to_string(), + std::declval&>()); + } #include "string.inl" diff --git a/include/cppcore/conversion/string.inl b/include/cppcore/conversion/string.inl index 51e2faa..52858b3 100644 --- a/include/cppcore/conversion/string.inl +++ b/include/cppcore/conversion/string.inl @@ -428,4 +428,14 @@ namespace std return os; } + template + inline auto operator<<(basic_ostream& os, X&& x) + -> decltype( + std::forward(x).to_string(), + std::declval&>()) + { + os << std::forward(x).to_string(); + return os; + } + }