problem with alias this and Tuple

Johann Lermer johann.lermer at
Tue Oct 12 09:30:57 UTC 2021

Hi all,

I have a problem with Tuples and struct templates that contain an 
alias this:
import std;

struct Element(T)
	T payload;
	alias payload this;

	this (T p)
		payload = p;

class Item {}

void main ()
	auto e = Element!Item (new Item());
	auto t = tuple(e);
dmd generates a warning: **Warning: struct Element has method 
toHash, however it cannot be called with const(Element!(Item)) 
Element.toHash defined here: 

The culprit seems to be the 'alias payload this'. When I remove 
that line, the code works. However, in my code, I need that 
alias. Any ideas, what's wrong or what I could do? Thanks.

More information about the Digitalmars-d-learn mailing list