www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Instantiating a Tuple with immutable fields.

reply Jose Armando Garcia <jsancio gmail.com> writes:
Hi,

I am trying to instantiate a Tuple that contains an immutable field.
Is there a way to do this with the current implementation? The
compiler gives me this error:

std/typecons.d(383): Error: can only initialize const member
_field_field_0 inside constructor
tuple_test.d(5): Error: template instance
std.typecons.Tuple!(immutable(int)).Tuple.__ctor!(int) error
instantiating
tuple_test.d(3): Error: function D main has no return statement, but
is expected to return a value of type int

here is the code:

import std.typecons;

int main()
{
  Tuple!(immutable(int)) var = Tuple!(immutable(int))(5);
  assert(var[0] == 5);
}

Thanks!
Jun 16 2011
parent bearophile <bearophileHUGS lycos.com> writes:
Jose Armando Garcia:

 I am trying to instantiate a Tuple that contains an immutable field.
 Is there a way to do this with the current implementation?

I think this is not yet possible. I am not sure, but maybe even small changes to conts are needed to fix this problem. Bye, bearophile
Jun 16 2011