static opSlice is not possible

Jonathan M Davis newsgroup.d at jmdavisprog.com
Thu Feb 15 23:31:23 UTC 2018


On Thursday, February 15, 2018 23:22:17 Adam D. Ruppe via Digitalmars-d-
learn wrote:
> On Thursday, 15 February 2018 at 23:20:42 UTC, Jonathan M Davis
>
> wrote:
> > The only overloaded operator that I'd expect to work as static
> > would be opCall, which I expect works primarily because of
> > functors but is useful for factory functions as well.
>
> static opCall is kinda weird in practice and frequently conflicts
> with non-static opCall as well as constructors. I don't suggest
> anyone try to use it (and in fact, I'd like to have it removed
> from the language)

If you use static opCall, then you don't use constructors, and you don't use
a non-static opCall. There are times where that makes perfect sense, and
plenty of times when it doesn't.

Personally, it's what I use when I need a factory function or in the rare
case where I have a singleton (e.g. std.datete.timezone's UTC and LocalTime
are both singletons that use static opCall to get at their single instance).
It wouldn't surprise me if folks trying to avoid the GC used static opCall
to create functors instead of using lambdas, but I don't recall ever doing
that personally.

So, I like having static opCall and use it periodically, and as such, I'd
hate to see it removed from the language, but it is true that its use is
somewhat limited.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list