[swift-evolution] [Completing Generics]
dgregor at apple.com
Wed Mar 9 17:57:34 CST 2016
> On Mar 9, 2016, at 4:28 AM, Erik Verbruggen <erik.verbruggen at me.com> wrote:
>> Generic constants
>> let constants could be allowed to have generic parameters, such that they produce differently-typed values depending on how they are used. For example, this is particularly useful for named literal values, e.g.,
>> let π<T : FloatLiteralConvertible>: T = 3.141592653589793238462643383279502884197169399
>> The Clang importer could make particularly good use of this when importing macros.
> I assume the following will fall under "constant expression":
> let 2π = 2 * π
That would involve inferring that 2π is a generic constant… could certainly be something to explore, but it’s somewhat new territory.
> Also, how does the clang-importer handle:
> #define M_DOUBLE_PI (2 * M_PI)
> Or rephrasing, this is specifically for the case where the initialiser only consists of a single literal token?
I was thinking of it in terms of a single literal token, but I’m pointing out the feature as a possibility, not doing the detailed design work that would be involved in making it real. It’s possible we could make the importer smarter in this regard.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution