Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
August 12, 2013 Parameterized aliases | ||||
---|---|---|---|---|
| ||||
Hi D community! What do you think of such templated aliases: template SomeTemplate(T1, T2) { } alias Partial(T) = SomeTemplate!(int, T); alias Specialized = Partial!float; // equivalent to SomeTemplate!(int, float) I think they could be pretty helpful and they should be relatively easy to implement. |
August 12, 2013 Re: Parameterized aliases | ||||
---|---|---|---|---|
| ||||
Posted in reply to Piotr Szturmaj | On Monday, 12 August 2013 at 20:06:16 UTC, Piotr Szturmaj wrote:
> Hi D community!
>
> What do you think of such templated aliases:
>
> template SomeTemplate(T1, T2) { }
>
> alias Partial(T) = SomeTemplate!(int, T);
>
> alias Specialized = Partial!float; // equivalent to SomeTemplate!(int, float)
>
> I think they could be pretty helpful and they should be relatively easy to implement.
That's a neat idea. I don't know much about the compiler, so I'm not sure how easy to implement it would be, but something tells me that it wouldn't be trivial.
|
August 12, 2013 Re: Parameterized aliases | ||||
---|---|---|---|---|
| ||||
Posted in reply to Piotr Szturmaj | On Monday, 12 August 2013 at 20:06:16 UTC, Piotr Szturmaj wrote:
> Hi D community!
>
> What do you think of such templated aliases:
>
> template SomeTemplate(T1, T2) { }
>
> alias Partial(T) = SomeTemplate!(int, T);
>
> alias Specialized = Partial!float; // equivalent to SomeTemplate!(int, float)
>
> I think they could be pretty helpful and they should be relatively easy to implement.
That's just been implemented actually. Try it on DMD head :)
I think they are actually called "template shorthand" or something, but yeah, it is basically parameterized aliases (also works with enums)
import std.typetuple;
alias Foo (U, T) = TypeTuple!(U, T);
alias FooInt(T) = Foo!(int, T);
void main()
{
alias UT = FooInt!(uint);
}
|
August 12, 2013 Re: Parameterized aliases | ||||
---|---|---|---|---|
| ||||
Posted in reply to Meta | On Monday, 12 August 2013 at 20:44:12 UTC, Meta wrote:
> That's a neat idea. I don't know much about the compiler, so I'm not sure how easy to implement it would be, but something tells me that it wouldn't be trivial.
Hmm, Dodra is right, I misunderstood.
|
August 12, 2013 Re: Parameterized aliases | ||||
---|---|---|---|---|
| ||||
Posted in reply to monarch_dodra | W dniu 12.08.2013 23:10, monarch_dodra pisze:
> On Monday, 12 August 2013 at 20:06:16 UTC, Piotr Szturmaj wrote:
>> Hi D community!
>>
>> What do you think of such templated aliases:
>>
>> template SomeTemplate(T1, T2) { }
>>
>> alias Partial(T) = SomeTemplate!(int, T);
>>
>> alias Specialized = Partial!float; // equivalent to SomeTemplate!(int,
>> float)
>>
>> I think they could be pretty helpful and they should be relatively
>> easy to implement.
>
> That's just been implemented actually. Try it on DMD head :)
Oh... I'm not following D as I used to. Thanks!
|
Copyright © 1999-2021 by the D Language Foundation