From c1ae1162b7fa9b69e2f841f6b5bce5d1fbfae36c Mon Sep 17 00:00:00 2001 From: bergmann Date: Mon, 29 Jul 2019 23:52:14 +0200 Subject: [PATCH] * Added specialization to write object to stream that has the method std::string to_string(void) --- include/cppcore/conversion/string.h | 9 +++++++++ include/cppcore/conversion/string.inl | 10 ++++++++++ 2 files changed, 19 insertions(+) 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; + } + }