October 05, 2019
I have some algorithmic code that uses the same dereferencing symbol quite often, like

.X

It's used in ranges, in predicates, in strings, etc and other things but is used a lot. The object it acts on has several fields and I would like to use them.

is there a way to use a abstract this easily?

alias C = X;

.C

then this is just .X

alias C = Y;

.Y

etc...

this obviously does not work though.



I do not want to use mixins nor have to write a lot of code to get something so simple.



October 05, 2019
On Saturday, 5 October 2019 at 00:39:03 UTC, Brett wrote:
> is there a way to use a abstract this easily?

I'd just use a traditional function for it, a little three liner.

----
struct Foo {
	int longName;
}

// note ufcs only works when declared top level so it cant be nested in main.... but you could nest it if you called it C(foo), of course
auto C(ref Foo a) {
	return a.longName;
}
void main() {

	Foo foo;

	foo.C;
}
----