You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Add support for defining template specializations. #467
Just an idea: Directly specifying the specialized template arguments in the declaration name comes from the current cpp1 syntax. In cpp2 syntax this could be moved nearly anywhere else. So a few examples:
same1: <T, U> type = {
this: std::false_type = ();
}
same1: <T> type<T, T> = { // 1: Have the specialized arguments defined in the type.
this: std::true_type = ();
}
same1: <T> specialize <T, T> type = { // 2: Have a new keyword 'specialize' which defines the specialization
this: std::true_type = ();
}
same1: <T> type = {
specialize: same1 = <T, T> // 3: Have a new keyword 'specialize' which defines the specialization in the body.
this: std::true_type = ();
}
same1: <T> type = {
same1: type == <T, T> // 4: Use the class name for the specialization.
this: std::true_type = ();
}
I think 1. would have problems with the specialization of function templates.
2 keeps the specialization near the current location.
3 would be more in line with the new definition of inheritance.
4 might be the weakest one.
Actually, first comes the template-argument-list (as lowered to Cpp1) before the template-parameter-list. Which matches "declaration follows use".
same1: <T, T> for <T> type = {
this: std::true_type = ();
}
I think in this example the declaration follows use would be broken.
First you declare the type, then the template-argument-list and afterwards the template-parameter-list. But the templates in the template-parameter-list would be used in the template-argument-list before they are declared.
In
same1: <T> specialize <T, T> type = { // 2: Have a new keyword 'specialize' which defines the specialization
this: std::true_type = ();
}
we would follow the left to right principle:
We declare a something with the name same1 it has the template-parameter-list <T> and is a specialization of the original template-parameters with the arguments <T, T> which is a type and has the definition ....
For a function it would look like:
f: <T> (a: T) -> T = { return 2 * a ; }
f: specialize <std::string> (a: std::string) -> std::string = {return a + a;}
Activity
leejy12 commentedon May 25, 2023
@JohelEGP Unrelated, but how will this code be compiled?
Because
is invalid Cpp1.
MaxSagebaum commentedon May 31, 2023
Just an idea: Directly specifying the specialized template arguments in the declaration name comes from the current cpp1 syntax. In cpp2 syntax this could be moved nearly anywhere else. So a few examples:
I think 1. would have problems with the specialization of function templates.
2 keeps the specialization near the current location.
3 would be more in line with the new definition of inheritance.
4 might be the weakest one.
My preference would be 2.
MaxSagebaum commentedon May 31, 2023
I think in this example the declaration follows use would be broken.
First you declare the type, then the template-argument-list and afterwards the template-parameter-list. But the templates in the template-parameter-list would be used in the template-argument-list before they are declared.
In
we would follow the left to right principle:
We declare a something with the name
same1it has the template-parameter-list<T>and is a specialization of the original template-parameters with the arguments<T, T>which is a type and has the definition ....For a function it would look like:
Xeverous commentedon Jun 3, 2025
Thinking about the order - specialization parameters should be after primary ones - otherwise it won't be read left-to-right.
I have came up with this:
MaxSagebaum commentedon Jun 4, 2025
I also think this is the best option. See also #467 (comment)