Abstract Const & Const Generics #7648
Replies: 2 comments 2 replies
-
Both would require considerable runtime changes, given |
Beta Was this translation helpful? Give feedback.
0 replies
-
Closing as a dupe of the linked issue, which already covers these concepts |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I just saw this: #7508, it is a great proposal, but before reading it, I thought of a simple syntactic sugar, no need to modify the existing type system. The example code is roughly as follows.
As you can see, it almost exclusively uses the existing C#, except for
abstract const
. Whenx
andy
are applied to the generic parameter, they are replaced with the generated struct; otherwise, they are treated as constants inside the user type.This idea was inspired by
abstract static
, which is mainly used in conjunction with generics, and the same goes forabstract const
. But constants are determined at compile time, while static variables are not. We know that constructed generics are also determined at compile time, andabstract const
has linked generics and constants together. So, by this syntactic sugar, we can merge them into the same thing. If constants can be used as types, they can be passed as generic parameters like types, thus achieving code sharing. For example, we can create something likeInlineArray<T, int size>
.Beta Was this translation helpful? Give feedback.
All reactions