auto & class members

Jonathan M Davis newsgroup.d at
Tue May 22 11:22:29 UTC 2018

On Tuesday, May 22, 2018 10:40:55 Robert M. Münch via Digitalmars-d-learn 
> This would require one wrap function per different lambda, right?
> Assume I have 50-100 of these. Maybe the myMessage value can be given
> as parameter and with this becomes more like a "filter factory". Not
> sure if this would work.

Pretty much the only time that this sort of thing pops up is when you have
to declare a variable that's a range (or some other similarly generic type)
separately from where it's initialized. I'd expect that your application
would have to be very large to have 50 - 100 instances of that. If you
really were hitting it a lot, then maybe it would make sense to try and
figure out a way to avoid having to declare a wrapper function, but in my
experience, this sort of thing simply doesn't come up all that often. It's
definitely an issue, and occasionally someone will come here and ask how to
deal with it, but I'd be worried if it came up often enough that creating a
wrapper function to deal with it was a problem.

The other way to fix the problem is to just call std.array.array on the
range to get a dynamic array. It does mean allocating, but you run into
fewer problems related to type inference, since you can then easily type
the type rather than having to use type inference to get it.

- Jonathan M Davis

More information about the Digitalmars-d-learn mailing list