www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Simple way to dereference common symbol

reply Brett <Brett gmail.com> writes:
I have some algorithmic code that uses the same dereferencing 
symbol quite often, like


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;


then this is just .X

alias C = Y;



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.
Oct 04 2019
parent Adam D. Ruppe <destructionator gmail.com> writes:
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; } ----
Oct 04 2019