Thread overview | ||||||
---|---|---|---|---|---|---|
|
March 30, 2008 Template Tuple Defaults | ||||
---|---|---|---|---|
| ||||
Is there a way to give default types to template tuple parameters? Like this: class Test (TTuple ... = [char, int] ) { // ... } void main () { Test t; // Equivalent to Test !(char, int) t; } Obviously, that does not compile. Thanks in advance, -Peter |
March 30, 2008 Re: Template Tuple Defaults | ||||
---|---|---|---|---|
| ||||
Posted in reply to Peter Neubauer | On Sun, 30 Mar 2008 06:06:00 +0200, Peter Neubauer <peterneubauer2@gmail.com> wrote:
> Is there a way to give default types to template tuple parameters?
> Like this:
>
>
> class Test (TTuple ... = [char, int] )
> {
> // ...
> }
>
> void main ()
> {
> Test t; // Equivalent to Test !(char, int) t;
> }
>
>
> Obviously, that does not compile.
>
> Thanks in advance,
> -Peter
This oughtta work (does on my confuser).
import std.typetuple;
class Test (TTuple ... = TypeTuple!(char, int) )
{
// ...
}
void main ()
{
Test t; // Equivalent to Test !(char, int) t;
}
-- Simen
|
March 30, 2008 Re: Template Tuple Defaults | ||||
---|---|---|---|---|
| ||||
Posted in reply to Simen Kjaeraas | Simen Kjaeraas schrieb:
> On Sun, 30 Mar 2008 06:06:00 +0200, Peter Neubauer <peterneubauer2@gmail.com> wrote:
>
>> Is there a way to give default types to template tuple parameters?
>> Like this:
>>
>>
>> class Test (TTuple ... = [char, int] )
>> {
>> // ...
>> }
>>
>> void main ()
>> {
>> Test t; // Equivalent to Test !(char, int) t;
>> }
>>
>>
>> Obviously, that does not compile.
>>
>> Thanks in advance,
>> -Peter
>
> This oughtta work (does on my confuser).
>
>
> import std.typetuple;
>
> class Test (TTuple ... = TypeTuple!(char, int) )
> {
> // ...
> }
>
> void main ()
> {
> Test t; // Equivalent to Test !(char, int) t;
> }
>
>
> -- Simen
Strange, all I get is this:
test.d(3): found '=' when expecting ')'
test.d(3): { } expected following aggregate declaration
test.d(3): no identifier for declarator TypeTuple!(char,int)
test.d(3): semicolon expected, not ')'
test.d(3): Declaration expected, not ')'
Maybe this is a difference between D 1.0 and 2.0? (I'm using 1.0)
-Peter
|
March 31, 2008 Re: Template Tuple Defaults | ||||
---|---|---|---|---|
| ||||
Posted in reply to Peter Neubauer | On Mon, 31 Mar 2008 01:29:10 +0200, Peter Neubauer <peterneubauer2@gmail.com> wrote:
> Simen Kjaeraas schrieb:
>> On Sun, 30 Mar 2008 06:06:00 +0200, Peter Neubauer <peterneubauer2@gmail.com> wrote:
>>
>>> Is there a way to give default types to template tuple parameters?
>>> Like this:
>>>
>>>
>>> class Test (TTuple ... = [char, int] )
>>> {
>>> // ...
>>> }
>>>
>>> void main ()
>>> {
>>> Test t; // Equivalent to Test !(char, int) t;
>>> }
>>>
>>>
>>> Obviously, that does not compile.
>>>
>>> Thanks in advance,
>>> -Peter
>> This oughtta work (does on my confuser).
>> import std.typetuple;
>> class Test (TTuple ... = TypeTuple!(char, int) )
>> {
>> // ...
>> }
>> void main ()
>> {
>> Test t; // Equivalent to Test !(char, int) t;
>> }
>> -- Simen
>
> Strange, all I get is this:
>
> test.d(3): found '=' when expecting ')'
> test.d(3): { } expected following aggregate declaration
> test.d(3): no identifier for declarator TypeTuple!(char,int)
> test.d(3): semicolon expected, not ')'
> test.d(3): Declaration expected, not ')'
>
> Maybe this is a difference between D 1.0 and 2.0? (I'm using 1.0)
>
> -Peter
Tested it again. Appears I did get part of it wrong.
class test(TTuple = TypeTuple!(char, int))
That works. Without the ellipsis. However, that is of course not what you wanted.
I do agree it should, though.
--Simen
|
Copyright © 1999-2021 by the D Language Foundation