-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The syntax is `specialize<specialization_arguments>` after the optional template parameter list. Some examples from the tests: ```Cpp2 std: namespace = { common_type: @struct @print specialize<outer, outer> type = { type: type == outer; } } v: <T> const i32 = 1; v: <> specialize<void> const i32 = 2; v: specialize<i64> const i32 = 3; v: <T> specialize<* T> std::optional<int> == 6; ```
- Loading branch information
Showing
10 changed files
with
266 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
t: @struct <T> type = { | ||
a: i32 = 1; | ||
} | ||
t: @struct <T> specialize<T> type requires std::is_void_v<T> = { | ||
b: i32 = 2; | ||
} | ||
t: @struct specialize<i64> type = { | ||
c: i32 = 3; | ||
} | ||
t: @struct specialize<* i8> type = { | ||
f: () 17; | ||
v: int == 29; | ||
} | ||
t: @struct <T> specialize<* T> type = { | ||
v: int == 17; | ||
f: () 29; | ||
} | ||
v: <T> const i32 = 1; | ||
v: <> specialize<void> const i32 = 2; | ||
v: specialize<i64> const i32 = 3; | ||
v: specialize<i16> std::optional<i32> == 4; | ||
v: <> specialize<i8> std::optional<i8> == 5; | ||
v: <T> specialize<* T> std::optional<int> == 6; | ||
main: () = { | ||
assert(t<i32>().a == 1); | ||
assert(t<void>().b == 2); | ||
assert(t<i64>().c == 3); | ||
assert(t<* i8>::f() == 17); | ||
assert(t<* i8>::v == 29); | ||
assert(t<* i16>::v == 17); | ||
assert(t<* i16>::f() == 29); | ||
assert(v<i32> == 1); | ||
assert(v<void> == 2); | ||
assert(v<i64> == 3); | ||
static_assert(v<i16> == 4); | ||
static_assert(v<i8> == 5); | ||
static_assert(v<* int> == 6); | ||
} |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
regression-tests/test-results/pure2-template-specialization.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
|
||
#define CPP2_IMPORT_STD Yes | ||
|
||
//=== Cpp2 type declarations ==================================================== | ||
|
||
|
||
#include "cpp2util.h" | ||
|
||
template<typename T> class t; | ||
|
||
|
||
//=== Cpp2 type definitions and function declarations =========================== | ||
|
||
template<typename T> class t { | ||
public: cpp2::i32 a {1}; | ||
}; | ||
template<typename T> requires( std::is_void_v<T> ) | ||
class t<T> {public: cpp2::i32 b {2}; | ||
}; | ||
template<> class t<cpp2::i64> { | ||
public: cpp2::i32 c {3}; | ||
}; | ||
template<> class t<cpp2::i8*> { | ||
public: [[nodiscard]] static auto f() -> auto; | ||
public: static const int v; | ||
}; | ||
template<typename T> class t<T*> { | ||
public: static const int v; | ||
public: [[nodiscard]] static auto f() -> auto; | ||
}; | ||
template<typename T> extern cpp2::i32 const v; | ||
|
||
#line 21 "pure2-template-specialization.cpp2" | ||
template<> std::optional<cpp2::i32> inline constexpr v<cpp2::i16> = 4; | ||
template<> std::optional<cpp2::i8> inline constexpr v<cpp2::i8> = 5; | ||
template<typename T> std::optional<int> inline constexpr v<T*> = 6; | ||
auto main() -> int; | ||
|
||
|
||
//=== Cpp2 function definitions ================================================= | ||
|
||
|
||
#line 11 "pure2-template-specialization.cpp2" | ||
[[nodiscard]] auto t<cpp2::i8*>::f() -> auto { return 17; } | ||
inline CPP2_CONSTEXPR int t<cpp2::i8*>::v = 29; | ||
|
||
#line 15 "pure2-template-specialization.cpp2" | ||
template <typename T> inline CPP2_CONSTEXPR int t<T*>::v = 17; | ||
template <typename T> [[nodiscard]] auto t<T*>::f() -> auto { return 29; } | ||
|
||
template<typename T> cpp2::i32 const v {1}; | ||
template<> cpp2::i32 const v<void> {2}; | ||
template<> cpp2::i32 const v<cpp2::i64> {3}; | ||
|
||
#line 24 "pure2-template-specialization.cpp2" | ||
auto main() -> int{ | ||
cpp2::Default.expects(t<cpp2::i32>().a == 1, ""); | ||
cpp2::Default.expects(t<void>().b == 2, ""); | ||
cpp2::Default.expects(t<cpp2::i64>().c == 3, ""); | ||
cpp2::Default.expects(t<cpp2::i8*>::f() == 17, ""); | ||
cpp2::Default.expects(t<cpp2::i8*>::v == 29, ""); | ||
cpp2::Default.expects(t<cpp2::i16*>::v == 17, ""); | ||
cpp2::Default.expects(t<cpp2::i16*>::f() == 29, ""); | ||
cpp2::Default.expects(v<cpp2::i32> == 1, ""); | ||
cpp2::Default.expects(v<void> == 2, ""); | ||
cpp2::Default.expects(v<cpp2::i64> == 3, ""); | ||
static_assert(v<cpp2::i16> == 4); | ||
static_assert(v<cpp2::i8> == 5); | ||
static_assert(v<int*> == 6); | ||
} | ||
|
2 changes: 2 additions & 0 deletions
2
regression-tests/test-results/pure2-template-specialization.cpp2.output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pure2-template-specialization.cpp2... ok (all Cpp2, passes safety checks) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.