Skip to content

Commit 91e1d79

Browse files
committed
Added template-parameter-declaration-list
Committing an evening's work I've been meaning to do for a while... easier because a `<` `>` parameter list is just another parameter list (same parsing function, minor generalization). Examples from the test case: f1: <T, U> (t:T, u:U) -> _ = { return t+u; } f2: <T:type, U:type> (t:T, u:U) -> _ = { return t+u; } f3: <T:_, U:_> () -> _ = { return T+U; } f4: <T: i8, U: i16> () -> _ = { return T+U; } main: () = { std::cout << "f1: (f1(1,1))$\n"; std::cout << "f2: (f2(2,2))$\n"; std::cout << "f3: (f3<3,3>())$\n"; std::cout << "f4: (f4<4,4>())$\n"; }
1 parent b34f23a commit 91e1d79

12 files changed

+279
-65
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
f1: <T, U> (t:T, u:U) -> _ = {
3+
return t+u;
4+
}
5+
6+
f2: <T:type, U:type> (t:T, u:U) -> _ = {
7+
return t+u;
8+
}
9+
10+
f3: <T:_, U:_> () -> _ = {
11+
return T+U;
12+
}
13+
14+
f4: <T: i8, U: i16> () -> _ = {
15+
return T+U;
16+
}
17+
18+
main: () = {
19+
std::cout << "f1: (f1(1,1))$\n";
20+
std::cout << "f2: (f2(2,2))$\n";
21+
std::cout << "f3: (f3<3,3>())$\n";
22+
std::cout << "f4: (f4<4,4>())$\n";
23+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
f1: 2
2+
f2: 4
3+
f3: 6
4+
f4: 8

regression-tests/test-results/clang-12/pure2-template-parameter-lists.cpp.output

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
f1: 2
2+
f2: 4
3+
f3: 6
4+
f4: 8

regression-tests/test-results/gcc-10/pure2-template-parameter-lists.cpp.output

Whitespace-only changes.

regression-tests/test-results/mixed-function-expression-and-std-for-each.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
std::for_each(
2626
CPP2_UFCS_0(begin, view),
2727
CPP2_UFCS_0(end, view),
28-
[](auto& x) { return x += "-ish"; }
28+
[](auto& x ) { return x += "-ish"; }
2929
);
3030

3131
// Initializating from a function expression
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
f1: 2
2+
f2: 4
3+
f3: 6
4+
f4: 8
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pure2-template-parameter-lists.cpp
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
#define CPP2_USE_MODULES Yes
3+
4+
#include "cpp2util.h"
5+
6+
7+
#line 2 "pure2-template-parameter-lists.cpp2"
8+
template<typename T, typename U> [[nodiscard]] auto f1(T const& t, U const& u) -> auto;
9+
#line 6 "pure2-template-parameter-lists.cpp2"
10+
template<typename T, typename U> [[nodiscard]] auto f2(T const& t, U const& u) -> auto;
11+
#line 10 "pure2-template-parameter-lists.cpp2"
12+
template<auto T, auto U> [[nodiscard]] auto f3() -> auto;
13+
#line 14 "pure2-template-parameter-lists.cpp2"
14+
template<cpp2::i8 T, cpp2::i16 U> [[nodiscard]] auto f4() -> auto;
15+
#line 18 "pure2-template-parameter-lists.cpp2"
16+
auto main() -> int;
17+
18+
//=== Cpp2 definitions ==========================================================
19+
20+
#line 1 "pure2-template-parameter-lists.cpp2"
21+
22+
template<typename T, typename U> [[nodiscard]] auto f1(T const& t, U const& u) -> auto{
23+
return t + u;
24+
}
25+
26+
template<typename T, typename U> [[nodiscard]] auto f2(T const& t, U const& u) -> auto{
27+
return t + u;
28+
}
29+
30+
template<auto T, auto U> [[nodiscard]] auto f3() -> auto{
31+
return T + U;
32+
}
33+
34+
template<cpp2::i8 T, cpp2::i16 U> [[nodiscard]] auto f4() -> auto{
35+
return T + U;
36+
}
37+
38+
auto main() -> int{
39+
std::cout << "f1: " + cpp2::to_string(f1(1, 1)) + "\n";
40+
std::cout << "f2: " + cpp2::to_string(f2(2, 2)) + "\n";
41+
std::cout << "f3: " + cpp2::to_string(f3<3,3>()) + "\n";
42+
std::cout << "f4: " + cpp2::to_string(f4<4,4>()) + "\n";
43+
}
44+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pure2-template-parameter-lists.cpp2... ok (all Cpp2, passes safety checks)
2+

0 commit comments

Comments
 (0)