| Thread overview | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
October 02, 2012 Re: Setting defaults to variadic template args | ||||
|---|---|---|---|---|
| ||||
On 10/2/12, Manu <turkeyman@gmail.com> wrote: > Does anyone have any clever tricks that will work in this scenario? Some magic tuple syntax? Without resorting to helper templates I only know of using this internal trick: struct Event(Args...) { static if (Args.length) alias Args T; else alias TypeTuple!(int, float) T; void F(T t) { } } Also there's a somewhat related bug but for variadic template functions with default arguments: http://d.puremagic.com/issues/show_bug.cgi?id=8687 | ||||
October 02, 2012 Re: Setting defaults to variadic template args | ||||
|---|---|---|---|---|
| ||||
Attachments:
| On 2 October 2012 16:24, Andrej Mitrovic <andrej.mitrovich@gmail.com> wrote:
> On 10/2/12, Manu <turkeyman@gmail.com> wrote:
> > Does anyone have any clever tricks that will work in this scenario? Some magic tuple syntax?
>
> Without resorting to helper templates I only know of using this internal trick:
>
> struct Event(Args...)
> {
> static if (Args.length)
> alias Args T;
> else
> alias TypeTuple!(int, float) T;
>
> void F(T t) { }
> }
>
> Also there's a somewhat related bug but for variadic template functions with default arguments: http://d.puremagic.com/issues/show_bug.cgi?id=8687
>
I think this is fine for my needs. Thanks!
| |||
October 02, 2012 Re: Setting defaults to variadic template args | ||||
|---|---|---|---|---|
| ||||
Attachments:
| On 2 October 2012 16:45, Manu <turkeyman@gmail.com> wrote:
> On 2 October 2012 16:24, Andrej Mitrovic <andrej.mitrovich@gmail.com>wrote:
>
>> On 10/2/12, Manu <turkeyman@gmail.com> wrote:
>> > Does anyone have any clever tricks that will work in this scenario? Some magic tuple syntax?
>>
>> Without resorting to helper templates I only know of using this internal trick:
>>
>> struct Event(Args...)
>> {
>> static if (Args.length)
>> alias Args T;
>> else
>> alias TypeTuple!(int, float) T;
>>
>> void F(T t) { }
>> }
>>
>> Also there's a somewhat related bug but for variadic template functions with default arguments: http://d.puremagic.com/issues/show_bug.cgi?id=8687
>>
>
> I think this is fine for my needs. Thanks!
>
Actually, this leaves a problem...
Distinction between:
Event x; // using defaults
and
Event!() x; // explicitly selecting none (which would fall back to the
defaults)
Is such a distinction possible? I presume not...
| |||
October 02, 2012 Re: Setting defaults to variadic template args | ||||
|---|---|---|---|---|
| ||||
On 10/2/12, Manu <turkeyman@gmail.com> wrote:
> Actually, this leaves a problem...
> Distinction between:
> Event x; // using defaults
> and
> Event!() x; // explicitly selecting none (which would fall back to the
> defaults)
>
> Is such a distinction possible? I presume not...
>
Well actually you can't use the first syntax at all with templates or templated types. :/
| ||||
October 02, 2012 Re: Setting defaults to variadic template args | ||||
|---|---|---|---|---|
| ||||
Attachments:
| On 2 October 2012 18:56, Andrej Mitrovic <andrej.mitrovich@gmail.com> wrote:
> On 10/2/12, Manu <turkeyman@gmail.com> wrote:
> > Actually, this leaves a problem...
> > Distinction between:
> > Event x; // using defaults
> > and
> > Event!() x; // explicitly selecting none (which would fall back to the
> > defaults)
> >
> > Is such a distinction possible? I presume not...
> >
>
> Well actually you can't use the first syntax at all with templates or templated types. :/
>
Errr, really? If the template has default args, surely you don't need to
specify any template args?
I'm sure I've done that before... :/
| |||
October 02, 2012 Re: Setting defaults to variadic template args | ||||
|---|---|---|---|---|
| ||||
On 10/2/12, Manu <turkeyman@gmail.com> wrote:
> Errr, really? If the template has default args, surely you don't need to
> specify any template args?
> I'm sure I've done that before... :/
>
The !() is required (it's like a sore thumb really..). I think this is
one of the first things I've ever complained about in the NG.
| ||||
October 02, 2012 Re: Setting defaults to variadic template args | ||||
|---|---|---|---|---|
| ||||
Attachments:
| On 2 October 2012 19:06, Andrej Mitrovic <andrej.mitrovich@gmail.com> wrote:
> On 10/2/12, Manu <turkeyman@gmail.com> wrote:
> > Errr, really? If the template has default args, surely you don't need to
> > specify any template args?
> > I'm sure I've done that before... :/
> >
>
> The !() is required (it's like a sore thumb really..). I think this is
> one of the first things I've ever complained about in the NG.
>
Are you sure it's not fixed? I'm sure I do it all the time... :/ Or I'm smoking some really good stuff.
| |||
October 02, 2012 Re: Setting defaults to variadic template args | ||||
|---|---|---|---|---|
| ||||
On 10/2/12, Manu <turkeyman@gmail.com> wrote:
> Are you sure it's not fixed? I'm sure I do it all the time... :/ Or I'm smoking some really good stuff.
I'd really like to see how you do it. If not, I'll have some of that stuff you're having, thanks. :p
| ||||
October 02, 2012 Re: Setting defaults to variadic template args | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Manu | On 2012-10-02 18:10, Manu wrote: > Are you sure it's not fixed? I'm sure I do it all the time... :/ > Or I'm smoking some really good stuff. It's not needed for functions templates. But it is needed for type templates. -- /Jacob Carlborg | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply