From 856df14d749014f11a583ade2fee988b076754cc Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 14 Oct 2023 22:48:16 +0800 Subject: Re-think about ToString. ToString for a class should lies in the same namespace of the class. Argument-dependent name lookup will help make Format work. The problem is it will hide ToString at parent namespace. But if you call ToString explicitly, it's you duty to use the ToString in correct namespace. --- include/cru/platform/GraphicsBase.h | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'include/cru/platform/GraphicsBase.h') diff --git a/include/cru/platform/GraphicsBase.h b/include/cru/platform/GraphicsBase.h index 88dc6ee2..f134e74d 100644 --- a/include/cru/platform/GraphicsBase.h +++ b/include/cru/platform/GraphicsBase.h @@ -5,7 +5,11 @@ #include "cru/common/Range.h" #include "cru/common/String.h" +#include #include +#include +#include +#include namespace cru::platform { struct Size; @@ -43,6 +47,10 @@ constexpr bool operator!=(const Point& left, const Point& right) { return !(left == right); } +inline String ToString(const Point& point) { + return Format(u"(x: {}, y: {})", point.x, point.y); +} + struct CRU_PLATFORM_API Size final { static const Size kMax; static const Size kZero; @@ -80,6 +88,10 @@ constexpr bool operator!=(const Size& left, const Size& right) { return !(left == right); } +inline String ToString(const Size& size) { + return Format(u"(width: {}, height: {})", size.width, size.height); +} + struct Thickness final { constexpr Thickness() : Thickness(0) {} @@ -278,14 +290,3 @@ constexpr bool operator!=(const Ellipse& left, const Ellipse& right) { using TextRange = Range; } // namespace cru::platform - -namespace cru { - -inline String ToString(const platform::Point& point) { - return Format(u"(x: {}, y: {})", point.x, point.y); -} -inline String ToString(const platform::Size& size) { - return Format(u"(width: {}, height: {})", size.width, size.height); -} - -} // namespace cru -- cgit v1.2.3