Thread overview
Template tuple parameters of classes
Jul 30, 2008
TSalm
Jul 31, 2008
ws
Jul 31, 2008
Tsalm
Aug 01, 2008
ws
Aug 02, 2008
tsalm
Aug 04, 2008
ws
July 30, 2008
Hello,

I've got a class MyClass :
  class MyClass(T) {}

And I need them in Template Tuple Parameter.
Something like this :
  void myFunction
          ( U:MyClass!(T),T , U2:MyClass!(T2),T2... )
          ( U myClass , U2 myClass2...)
  	  {  /* ...some code... */ }


call by :
  MyClass!(int) mine1;
  MyClass!(double) mine2;
  MyClass!(char) mine3;
  myFunction( mine1 , mine2 , mine3 );

but.of course, 'myFunction' is incorrect...
How to declare it ?

Thanks in advance,
TSalm
July 31, 2008
TSalm Wrote:

> Hello,
> 
> I've got a class MyClass :
>   class MyClass(T) {}
> 
> And I need them in Template Tuple Parameter.
> Something like this :
>   void myFunction
>           ( U:MyClass!(T),T , U2:MyClass!(T2),T2... )
>           ( U myClass , U2 myClass2...)
>   	  {  /* ...some code... */ }
> 
> 
> call by :
>   MyClass!(int) mine1;
>   MyClass!(double) mine2;
>   MyClass!(char) mine3;
>   myFunction( mine1 , mine2 , mine3 );
> 
> but.of course, 'myFunction' is incorrect...
> How to declare it ?
> 
> Thanks in advance,
> TSalm

Perhaps this post by Jarrett is of help: http://lists.puremagic.com/pipermail/digitalmars-d/2007-October/026373.html
July 31, 2008
On Wed, 30 Jul 2008 21:33:05 -0400, ws wrote:

> TSalm Wrote:
>> I've got a class MyClass :
>>   class MyClass(T) {}
>> 
>> And I need them in Template Tuple Parameter. Something like this :
>>   void myFunction
>>           ( U:MyClass!(T),T , U2:MyClass!(T2),T2... ) ( U myClass , U2
>>           myClass2...)
>>   	  {  /* ...some code... */ }
>> 
>> 
>> call by :
>>   MyClass!(int) mine1;
>>   MyClass!(double) mine2;
>>   MyClass!(char) mine3;
>>   myFunction( mine1 , mine2 , mine3 );
>> 
>> but.of course, 'myFunction' is incorrect... How to declare it ?
>> 
> 
> Perhaps this post by Jarrett is of help: http://lists.puremagic.com/pipermail/digitalmars-d/2007-
October/026373.html

It is very interresting. Thanks.


I'm trying this :
/* -------------------- */
class MyClass(T)
{
 T getTypeMin() {return T.min;}
}

template Print(U ...)
{
  void Print()
  {
    Stdout(U[0].getTypeMin()).newline;
  }
}

void main()
{
  MyClass!(int) mine1;
  MyClass!(double) mine2;
  MyClass!(float) mine3;

  Print!(mine1,mine2,mine3);
}
/* -------------------- */

But the execution send me an Access Violation !?
August 01, 2008
Tsalm Wrote:

> On Wed, 30 Jul 2008 21:33:05 -0400, ws wrote:
> 
> > TSalm Wrote:
> >> I've got a class MyClass :
> >>   class MyClass(T) {}
> >> 
> >> And I need them in Template Tuple Parameter. Something like this :
> >>   void myFunction
> >>           ( U:MyClass!(T),T , U2:MyClass!(T2),T2... ) ( U myClass , U2
> >>           myClass2...)
> >>   	  {  /* ...some code... */ }
> >> 
> >> 
> >> call by :
> >>   MyClass!(int) mine1;
> >>   MyClass!(double) mine2;
> >>   MyClass!(char) mine3;
> >>   myFunction( mine1 , mine2 , mine3 );
> >> 
> >> but.of course, 'myFunction' is incorrect... How to declare it ?
> >> 
> > 
> > Perhaps this post by Jarrett is of help: http://lists.puremagic.com/pipermail/digitalmars-d/2007-
> October/026373.html
> 
> It is very interresting. Thanks.
> 
> 
> I'm trying this :
> /* -------------------- */
> class MyClass(T)
> {
>  T getTypeMin() {return T.min;}
> }
> 
> template Print(U ...)
> {
>   void Print()
>   {
>     Stdout(U[0].getTypeMin()).newline;
>   }
> }
> 
> void main()
> {
>   MyClass!(int) mine1;
>   MyClass!(double) mine2;
>   MyClass!(float) mine3;
> 
>   Print!(mine1,mine2,mine3);
> }
> /* -------------------- */
> 
> But the execution send me an Access Violation !?

The variables are not allocated.
Try this:
class MyClass(T)
{
T getTypeMin() {return T.min;}
}
template Print(U ...)
{
  void Print()
  {
    static if (U.length >= 1)
   {
     Stdout(U[0].getTypeMin());
     Print!(U[1..$]);
   }
 }
}

void main()
{
  auto mine1 = new MyClass!(int);
  auto mine2 = new MyClass!(double);
  auto mine3 = new MyClass!(float);
  Print!(mine1,mine2,mine3);
}

August 02, 2008
Le Fri, 01 Aug 2008 09:52:46 +0200, ws <wisiong@gmail.com> a écrit:

> Tsalm Wrote:
>
>> On Wed, 30 Jul 2008 21:33:05 -0400, ws wrote:
>>
>> > TSalm Wrote:
>> >> I've got a class MyClass :
>> >>   class MyClass(T) {}
>> >>
>> >> And I need them in Template Tuple Parameter. Something like this :
>> >>   void myFunction
>> >>           ( U:MyClass!(T),T , U2:MyClass!(T2),T2... ) ( U myClass ,  
>> U2
>> >>           myClass2...)
>> >>   	  {  /* ...some code... */ }
>> >>
>> >>
>> >> call by :
>> >>   MyClass!(int) mine1;
>> >>   MyClass!(double) mine2;
>> >>   MyClass!(char) mine3;
>> >>   myFunction( mine1 , mine2 , mine3 );
>> >>
>> >> but.of course, 'myFunction' is incorrect... How to declare it ?
>> >>
>> >
>> > Perhaps this post by Jarrett is of help:
>> > http://lists.puremagic.com/pipermail/digitalmars-d/2007-
>> October/026373.html
>>
>> It is very interresting. Thanks.
>>
>>
>> I'm trying this :
>> /* -------------------- */
>> class MyClass(T)
>> {
>>  T getTypeMin() {return T.min;}
>> }
>>
>> template Print(U ...)
>> {
>>   void Print()
>>   {
>>     Stdout(U[0].getTypeMin()).newline;
>>   }
>> }
>>
>> void main()
>> {
>>   MyClass!(int) mine1;
>>   MyClass!(double) mine2;
>>   MyClass!(float) mine3;
>>
>>   Print!(mine1,mine2,mine3);
>> }
>> /* -------------------- */
>>
>> But the execution send me an Access Violation !?
>
> The variables are not allocated.
> Try this:
> class MyClass(T)
> {
> T getTypeMin() {return T.min;}
> }
> template Print(U ...)
> {
>   void Print()
>   {
>     static if (U.length >= 1)
>    {
>      Stdout(U[0].getTypeMin());
>      Print!(U[1..$]);
>    }
>  }
> }
>
> void main()
> {
>   auto mine1 = new MyClass!(int);
>   auto mine2 = new MyClass!(double);
>   auto mine3 = new MyClass!(float);
>   Print!(mine1,mine2,mine3);
> }
>
It work.
thanks !

Another question in the same sense : is there a way to do this :
( the aim is to work with the type   (T)  of the instance of MyClass    )

/* --------------------------------------- */
import tango.io.Stdout;

class MyClass(T)
{}

template Print(U: MyClass!(T),T ...)
{
  void Print()
  {
    static if (U.length >= 1)
   {
     Stdout(T[0].sizeof);
     Print!(U[1..$]);
   }
 }
}

void main()
{
  auto mine1 = new MyClass!(int);
  auto mine2 = new MyClass!(double);
  auto mine3 = new MyClass!(float);
  Print!(mine1,mine2,mine3);
}
/* --------------------------------------- */
August 04, 2008
tsalm Wrote:

> Another question in the same sense : is there a way to do this :
> ( the aim is to work with the type   (T)  of the instance of MyClass    )
> 
> /* --------------------------------------- */
> import tango.io.Stdout;
> 
> class MyClass(T)
> {}
> 
> template Print(U: MyClass!(T),T ...)
> {
>    void Print()
>    {
>      static if (U.length >= 1)
>     {
>       Stdout(T[0].sizeof);
>       Print!(U[1..$]);
>     }
>   }
> }
> 
> void main()
> {
>    auto mine1 = new MyClass!(int);
>    auto mine2 = new MyClass!(double);
>    auto mine3 = new MyClass!(float);
>    Print!(mine1,mine2,mine3);
> }
> /* --------------------------------------- */

If you are looking for variadic template parameters that work together with constraint, i am not sure if it can be done at the moment. Maybe when concept is ready?
http://www.digitalmars.com/d/2.0/concepts.html