www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Return type depends on his argument's template

reply TSalm <tsalm free.fr> writes:
Hello,

Is there a way to do this :

/* ------------------------------------- */
class A(T)
{
  // some methods
}

class B
{
  T getValue( A(T) a )  // <-- Here, the type of the return value 
                        //     is the type T of A(T)
  {  /* some code */  }
}
/* ------------------------------------- */


thanks in advance,
TSalm
Jul 05 2008
parent reply "Simen Kjaeraas" <simen.kjaras gmail.com> writes:
TSalm <tsalm free.fr> wrote:

 Hello,

 Is there a way to do this :

 /* ------------------------------------- */
 class A(T)
 {
   // some methods
 }

 class B
 {
   T getValue( A(T) a )  // <-- Here, the type of the return value
                         //     is the type T of A(T)
   {  /* some code */  }
 }
 /* ------------------------------------- */


 thanks in advance,
 TSalm
If I understand you correctly, this can be done like so: class A(T) { } class B { T getValue(U : A!(T), T)(U a) { // some code } } -- Simen
Jul 05 2008
parent TSalm <tsalm free.fr> writes:
Great !
Thanks Simen


On Sat, 05 Jul 2008 11:34:29 +0200, Simen Kjaeraas wrote:

 TSalm <tsalm free.fr> wrote:
 
 Hello,

 Is there a way to do this :

 /* ------------------------------------- */ class A(T)
 {
   // some methods
 }

 class B
 {
   T getValue( A(T) a )  // <-- Here, the type of the return value
                         //     is the type T of A(T)
   {  /* some code */  }
 }
 /* ------------------------------------- */


 thanks in advance,
 TSalm
If I understand you correctly, this can be done like so: class A(T) { } class B { T getValue(U : A!(T), T)(U a) { // some code } } -- Simen
Jul 06 2008