typedef behavior

Alex sascha.orlov at gmail.com
Fri Feb 9 23:45:56 UTC 2018


A question about Typedef usage:
Say, I have the following circumstances

/// --- code --- ///

import std.typecons;

void main()
{
	MyEA ea;
	MyEB eb;
	ea.tarr.length = 5;
	static assert(!is(MyEA == MyEB));
	static assert(!is(MyEA == E));
	static assert(!is(MyEB == E));
	assert(ea.tarr.length == eb.tarr.length); // line 11
	assert(ea.tarr.length != eb.tarr.length); // line 12
}

struct T
{
	size_t i;
}

struct E
{
	size_t i;
	static T[] tarr;
}

alias MyEA = Typedef!(E, E.init, "A"); // line 26
alias MyEB = Typedef!(E, E.init, "B"); // line 27

/// --- code ends --- ///

Line 12 yields an assertion error, while line 11 does not.
This tells me, that despite the fact the types MyEA and MyEB are 
different they still share the static array, which would 
contradict the definition of static.

I suppose, the tricky thing is to tweak the init property of the 
typedefs in lines 26/27 to avoid this clash. How to manage this?


More information about the Digitalmars-d-learn mailing list