From b43d44bf69ea58035ad6146f71e8e3b2ee175e38 Mon Sep 17 00:00:00 2001 From: Dup4 Date: Mon, 4 Jul 2022 00:44:41 +0800 Subject: [PATCH] refactor: global to_string -> ToString --- include/snapshot/internal/string_utility.h | 11 ++++++++++- include/snapshot/types_check/has_global_to_string.h | 2 +- test/internal/string_utility_test.cc | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/include/snapshot/internal/string_utility.h b/include/snapshot/internal/string_utility.h index 5673e39..d067a33 100644 --- a/include/snapshot/internal/string_utility.h +++ b/include/snapshot/internal/string_utility.h @@ -13,6 +13,15 @@ namespace snapshot { +namespace internal { + +template , bool> = true> +inline std::string VisitGlobalToString(const T& t) { + return ToString(t); +} + +} // namespace internal + class StringUtility { friend class StringUtilityTest; @@ -24,7 +33,7 @@ class StringUtility { template , bool> = true> static std::string ToString(const T& t) { - return to_string(t); + return internal::VisitGlobalToString(t); } template , bool> = true> diff --git a/include/snapshot/types_check/has_global_to_string.h b/include/snapshot/types_check/has_global_to_string.h index 76e578f..d5a7960 100644 --- a/include/snapshot/types_check/has_global_to_string.h +++ b/include/snapshot/types_check/has_global_to_string.h @@ -9,7 +9,7 @@ template class has_global_to_string { private: template - static auto check(int) -> decltype(to_string(std::declval()), std::true_type()); + static auto check(int) -> decltype(ToString(std::declval()), std::true_type()); template static std::false_type check(...); diff --git a/test/internal/string_utility_test.cc b/test/internal/string_utility_test.cc index b3261e7..b3e554e 100644 --- a/test/internal/string_utility_test.cc +++ b/test/internal/string_utility_test.cc @@ -31,7 +31,7 @@ class CustomToString1 { int z; }; -string to_string(const CustomToString1& c) { +string ToString(const CustomToString1& c) { return to_string(c.x) + " " + to_string(c.y) + " " + to_string(c.z) + "\n"; }