Instantiating a Tuple with immutable fields.

Jose Armando Garcia jsancio at gmail.com
Thu Jun 16 16:09:13 PDT 2011


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!


More information about the Digitalmars-d-learn mailing list