When is a slice not a slice?

Alix Pexton via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jun 5 12:46:09 PDT 2014


In CTFE it seems. Only tested with DMD on Windows though. Is this a 
known limitation, or a bug, I couldn't find anything that seemed to 
match it in the bugzilla.


import std.array;

struct DataAndView
{
	int[] data, view;

	this(int x)
	{
		data = [1, 2, 3, 4, 5];
		view = data[x .. $];
	}
}

unittest
{
	auto a = DataAndView(1);
	assert (sameTail(a.data, a.view));
	enum b = DataAndView(1);
	assert (!sameTail(b.data, b.view));
}


More information about the Digitalmars-d-learn mailing list