Skip to content

Commit

Permalink
refactor: global to_string -> ToString
Browse files Browse the repository at this point in the history
  • Loading branch information
Dup4 committed Jul 3, 2022
1 parent f445c0c commit b43d44b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
11 changes: 10 additions & 1 deletion include/snapshot/internal/string_utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@

namespace snapshot {

namespace internal {

template <typename T, std::enable_if_t<internal::has_global_to_string_v<T>, bool> = true>
inline std::string VisitGlobalToString(const T& t) {
return ToString(t);
}

} // namespace internal

class StringUtility {
friend class StringUtilityTest;

Expand All @@ -24,7 +33,7 @@ class StringUtility {

template <typename T, std::enable_if_t<internal::has_global_to_string_v<T>, bool> = true>
static std::string ToString(const T& t) {
return to_string(t);
return internal::VisitGlobalToString(t);
}

template <typename T, std::enable_if_t<internal::has_class_internal_to_string_v<T>, bool> = true>
Expand Down
2 changes: 1 addition & 1 deletion include/snapshot/types_check/has_global_to_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ template <typename T>
class has_global_to_string {
private:
template <typename U>
static auto check(int) -> decltype(to_string(std::declval<U>()), std::true_type());
static auto check(int) -> decltype(ToString(std::declval<U>()), std::true_type());

template <typename U>
static std::false_type check(...);
Expand Down
2 changes: 1 addition & 1 deletion test/internal/string_utility_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

Expand Down

0 comments on commit b43d44b

Please sign in to comment.