www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Put Tuple in templates in a class fails

reply "Xan" <xancorreu gmail.com> writes:
Hi,

I have this code: https://gist.github.com/2653620

and I want to change
public class Algorisme(U,V) {

to
public class Algorisme(V,U...) {

but when I do: https://gist.github.com/2653643

I get error:
prova_amb_tuples_a_Algorisme.d:84: Error: 'alg' is not of 
arithmetic type, it is a 
prova_amb_tuples_a_Algorisme.Algorisme!(int,int).Algorisme
prova_amb_tuples_a_Algorisme.d:84: Error: 'alg2' is not of 
arithmetic type, it is a 
prova_amb_tuples_a_Algorisme.Algorisme!(int,int).Algorisme



What fails?

Thanks in advance,
Xan.
May 10 2012
parent reply Philippe Sigaud <philippe.sigaud gmail.com> writes:
On Thu, May 10, 2012 at 4:48 PM, Xan <xancorreu gmail.com> wrote:

 public class Algorisme(V,U...) {

 but when I do: https://gist.github.com/2653643

 I get error:
 prova_amb_tuples_a_Algorisme.d:84: Error: 'alg' is not of arithmetic type,
 it is a prova_amb_tuples_a_Algorisme.Algorisme!(int,int).Algorisme
 prova_amb_tuples_a_Algorisme.d:84: Error: 'alg2' is not of arithmetic type,
 it is a prova_amb_tuples_a_Algorisme.Algorisme!(int,int).Algorisme
You have to help the type-deduction algorithm a bit. By exposing the Domini/Codomini tuples, for example. Here: https://gist.github.com/2655583 See the new template constraint on lines 52-54 and the helper template at the beginning of the file. Also, in the string example, you inverted the domain and codomain. Btw, I'm not sure you can compose function with tuple-domains/codomains in general... Philippe
May 10 2012
parent "Xan" <xancorreu gmail.com> writes:
Thank you very much, Philippe.

I have several questions:

* Why do you think I can't compose functions with tuples? Your 
implentation does exactly this, isn't?

* What is RHS?

Thanks,
Xan.

On Thursday, 10 May 2012 at 20:17:12 UTC, Philippe Sigaud wrote:
 On Thu, May 10, 2012 at 4:48 PM, Xan <xancorreu gmail.com> 
 wrote:

 public class Algorisme(V,U...) {

 but when I do: https://gist.github.com/2653643

 I get error:
 prova_amb_tuples_a_Algorisme.d:84: Error: 'alg' is not of 
 arithmetic type,
 it is a 
 prova_amb_tuples_a_Algorisme.Algorisme!(int,int).Algorisme
 prova_amb_tuples_a_Algorisme.d:84: Error: 'alg2' is not of 
 arithmetic type,
 it is a 
 prova_amb_tuples_a_Algorisme.Algorisme!(int,int).Algorisme
You have to help the type-deduction algorithm a bit. By exposing the Domini/Codomini tuples, for example. Here: https://gist.github.com/2655583 See the new template constraint on lines 52-54 and the helper template at the beginning of the file. Also, in the string example, you inverted the domain and codomain. Btw, I'm not sure you can compose function with tuple-domains/codomains in general... Philippe
May 13 2012