Range Redesign: Empty Ranges

H. S. Teoh hsteoh at qfbox.info
Wed Mar 6 21:28:26 UTC 2024


On Wed, Mar 06, 2024 at 08:53:55PM +0000, Dukc via Digitalmars-d wrote:
> On Wednesday, 6 March 2024 at 17:57:36 UTC, H. S. Teoh wrote:
[...]
> > This makes .choose essentially useless outside of trivial cases.
> 
> It's far from useless, it's only like taking an enum argument and
> `switch`ing on it instead of taking a delerate argument. Certainly
> works but means you have to list all your cases in the function, which
> may or may not be what you want.

Well yes, so it's very limited in what it can do. In the cases where you
can't list all cases in the call to .choose, or where you don't want to
for code cleanliness reasons, it's useless.


> The gripe I have with `std.range.interface` is lack of attributes in
> the virtual functions. I don't think any simple attribute set alone
> would solve the problem well.
[...]

The problem is that the base class cannot predict which restrictive
attributes will be applied to a derived class override of a method. You
cannot override a @safe base class method with a @system derived class
method, for example. So it must settle for the most permissive
attributes.  But that means the code that receives a base class
reference must handle the most permissive attributes as well; a @safe
function would not be able to invoke a @safe method in a derived class
if the only reference it has to the derived object is a base class
reference.  There's no way around this except to get rid of
(restrictive) attributes altogether.


T

-- 
EMACS = Extremely Massive And Cumbersome System


More information about the Digitalmars-d mailing list