www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Is this supposed to be a bug?

reply Daniel Ribeiro Maciel <daniel.maciel gmail.com> writes:
void handler( alias dg )()
{
  alias ParameterTypeTuple!( typeof(dg) ) TParamTuple;
  alias ReturnType!(dg) TResult;

  TParamTuple params;
  foreach( ref param; params )
  {}
}

double hello( double i )
{
  writefln( "zomfg ", i );
}

int main( in string[] )
{
  handler!(hello)();
}

This code yields error on "foreach( ref param; params )": Error : No storage
class for value param

Best regards,
Daniel
Nov 02 2008
parent "Jarrett Billingsley" <jarrett.billingsley gmail.com> writes:
On Sun, Nov 2, 2008 at 7:56 PM, Daniel Ribeiro Maciel
<daniel.maciel gmail.com> wrote:
 void handler( alias dg )()
 {
  alias ParameterTypeTuple!( typeof(dg) ) TParamTuple;
  alias ReturnType!(dg) TResult;

  TParamTuple params;
  foreach( ref param; params )
  {}
 }

 double hello( double i )
 {
  writefln( "zomfg ", i );
 }

 int main( in string[] )
 {
  handler!(hello)();
 }

 This code yields error on "foreach( ref param; params )": Error : No storage
class for value param

 Best regards,
 Daniel

For some reason you can't use 'ref' on tuple foreaches. You'll just have to use the index-value version: foreach(i, param; params) { /* set params[i] here */ }
Nov 02 2008