Skip to content

Commit 426e833

Browse files
committed
Fix as<std::string> based on JohelEGP feedback
1 parent 978d198 commit 426e833

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

include/cpp2util.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -928,12 +928,13 @@ inline auto to_string(std::same_as<std::any> auto const&) -> std::string
928928
return "std::any";
929929
}
930930

931-
inline auto to_string(bool b) -> std::string
931+
inline auto to_string(std::same_as<bool> auto b) -> std::string
932932
{
933933
return b ? "true" : "false";
934934
}
935935

936936
template<typename T>
937+
requires (!std::same_as<T, bool>)
937938
inline auto to_string(T&& t) -> std::string
938939
requires requires { std::to_string(t); }
939940
{
@@ -945,7 +946,8 @@ inline auto to_string(char const& t) -> std::string
945946
return std::string{t};
946947
}
947948

948-
inline auto to_string(char const* s) -> std::string
949+
template <std::same_as<char const*> X>
950+
inline auto to_string(X& s) -> std::string
949951
{
950952
return std::string{s};
951953
}
@@ -1037,19 +1039,13 @@ inline auto to_string(auto&& value, std::string_view) -> std::string
10371039
template <typename T>
10381040
concept has_to_string_overload = requires{ static_cast<std::string (*)(T const&)>(&to_string); };
10391041

1040-
template< std::same_as<std::string> C, non_string X>
1042+
template< std::same_as<std::string> C, typename X>
10411043
requires has_to_string_overload<X>
10421044
auto as( X&& x) -> C
10431045
{
10441046
return cpp2::to_string(CPP2_FORWARD(x));
10451047
}
10461048

1047-
template< std::same_as<std::string> C>
1048-
auto as(bool x) -> C
1049-
{
1050-
return cpp2::to_string(x);
1051-
}
1052-
10531049
template< std::same_as<std::string> C, std::size_t N>
10541050
auto as(const char (&x)[N]) -> C
10551051
{

0 commit comments

Comments
 (0)