First life-signs of type functions
Steven Schveighoffer
schveiguy at gmail.com
Tue May 12 16:12:42 UTC 2020
On 5/12/20 11:42 AM, Stefan Koch wrote:
> On Tuesday, 12 May 2020 at 14:41:52 UTC, Max Samukha wrote:
>> On Tuesday, 12 May 2020 at 14:14:21 UTC, Stefan Koch wrote:
>>> are you sure that that is the case for alias declarations?
>>> For me
>>> alias a = "Foo";
>>> causes Error: basic type expected, not "Foo"
>>> Which is identical to how they behave in type functions;
>>
>> Can this old design flaw be fixed? 'alias a = Alias!"Foo"' shouldn't
>> be necessary. We should be able to alias directly everything that we
>> can pass to an alias template parameter.
>
> Which name does "Foo" have?
alias x = Alias!"Foo";
pragma(msg, __traits(identifier, x)); // `a`
This is the name the Alias template gives to its parameter.
> There is a good reason for separating Symbols and literals.
Whether or not you like it, you can alias literals to template
parameters. If type functions cannot do this, we will be stuck with
using templates for many things, and I can totally envision this pattern
happening:
string foo(string[] symbolnames, alias dummy = __dummy)
{
// do something with symbolnames, ignore dummy
}
to force a type function instead of using CTFE when you want to
manipulate a compile-time list of strings.
It reminds me of what people would resort to for a static foreach over a
tuple when all they wanted was the index (before static foreach existed).
-Steve
More information about the Digitalmars-d
mailing list