Skip to content

Commit dda5c9f

Browse files
committed
Follow-up to #49 to move catchall overload up
And add regression tests for the compositions enabled by #49
1 parent f874f4c commit dda5c9f

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

include/cpp2util.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,10 @@ template <class F>
751751
//
752752
//-----------------------------------------------------------------------
753753
//
754+
inline auto to_string(...) -> std::string {
755+
return "(customize me - no cpp2::to_string overload exists for this type)";
756+
}
757+
754758
template<typename T>
755759
inline auto to_string(T const& t) -> std::string
756760
requires requires { std::to_string(t); }
@@ -824,10 +828,6 @@ inline auto to_string(std::tuple<Ts...> const& t) -> std::string
824828
}
825829
}
826830

827-
inline auto to_string(...) -> std::string {
828-
return "(customize me - no cpp2::to_string overload exists for this type)";
829-
}
830-
831831

832832
//-----------------------------------------------------------------------
833833
//

regression-tests/mixed-string-interpolation.cpp2

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <utility>
44
#include <tuple>
55

6+
struct custom_struct_with_no_stringize_customization { } custom;
7+
68
main: () -> int = {
79
a := 2;
810
b: std::optional<int> = ();
@@ -35,4 +37,15 @@ main: () -> int = {
3537
std::cout << "tup1 = (tup1)$\n";
3638
std::cout << "tup2 = (tup2)$\n";
3739
std::cout << "tup3 = (tup3)$\n";
40+
41+
p: std::pair<std::string_view, std::optional<std::string>> = ("first", std::nullopt);
42+
std::cout << "p = (p)$\n";
43+
44+
t: std::tuple<double, std::optional<std::pair<std::string_view, int>>, std::optional<std::tuple<int, int, int>>> = (3.14, std::nullopt, std::nullopt);
45+
std::cout << "t = (t)$\n";
46+
47+
vv: std::variant<int, std::string, std::pair<int, double> > = ();
48+
std::cout << "vv = (vv)$\n";
49+
50+
std::cout << "custom = (custom)$\n";
3851
}

regression-tests/test-results/mixed-string-interpolation.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
#include <utility>
88
#include <tuple>
99

10+
struct custom_struct_with_no_stringize_customization { } custom;
11+
1012
[[nodiscard]] auto main() -> int;
1113

1214
//=== Cpp2 definitions ==========================================================
1315

14-
#line 5 "mixed-string-interpolation.cpp2"
16+
#line 7 "mixed-string-interpolation.cpp2"
1517

1618
[[nodiscard]] auto main() -> int{
1719
auto a { 2 };
@@ -45,4 +47,15 @@
4547
std::cout << "tup1 = " + cpp2::to_string(tup1) + "\n";
4648
std::cout << "tup2 = " + cpp2::to_string(tup2) + "\n";
4749
std::cout << "tup3 = " + cpp2::to_string(tup3) + "\n";
50+
51+
std::pair<std::string_view,std::optional<std::string>> p { "first", std::nullopt };
52+
std::cout << "p = " + cpp2::to_string(p) + "\n";
53+
54+
std::tuple<double,std::optional<std::pair<std::string_view,int>>,std::optional<std::tuple<int,int,int>>> t { 3.14, std::nullopt, std::nullopt };
55+
std::cout << "t = " + cpp2::to_string(t) + "\n";
56+
57+
std::variant<int,std::string,std::pair<int,double>> vv { };
58+
std::cout << "vv = " + cpp2::to_string(vv) + "\n";
59+
60+
std::cout << "custom = " + cpp2::to_string(custom) + "\n";
4861
}

0 commit comments

Comments
 (0)