@safe(bool)

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Thu Aug 17 18:43:42 PDT 2017


On Thursday, August 17, 2017 19:21:16 Timon Gehr via Digitalmars-d wrote:
> On 17.08.2017 18:36, HyperParrow wrote:
> > On Thursday, 17 August 2017 at 16:32:20 UTC, bitwise wrote:
> >> This came to mind while working on a set of containers.
> >>
> >> [...]
> >> One solution could be this:
> >>
> >> struct Container(T, bool safetyOn = true)
> >> {
> >>
> >>     static if(safe)
> >>
> >>         RefCounted!(T[]) data;
> >>
> >>     else
> >>
> >>         T[] data;
> >>
> >>     auto opSlice() @safe(safetyOn) {
> >>
> >>         return Range(data, 0, data.length);
> >>
> >>     }
> >>
> >> }
> >>
> >> A similar solution could be applied to @nogc as well.
> >
> > Yeah, i like it more than
> > https://github.com/dlang/DIPs/blob/master/DIPs/DIP1012.md.
>
> That makes little sense to me, as DIP 1012 is strictly more general.

Whereas this solves the problem with DIP 1012 claims to be solving without
adding a bunch of extra stuff that IMHO makes the built-in attributes more
complicated for no real benefit as well as having some stuff in it that
would effectively split the language into multiple variants where code will
compile with some but not others (most notably, allowing for the default
@safety level to be globally altered as opposed to doing something nice and
portable like @safe: at the top of a module). As I explained in the initial
discussion in DIP 1012, it does a whole pile of stuff that has nothing to do
with its stated goal, and I think that most of the other stuff that it does
is detrimental, whereas if what's proposed here were implemented for more
than just @safe, it would actually solve the stated goal of allowing
attributes to be negated and thus fix the problem that doing something like
putting final: at the top of a class can't be undone.

Andrei previously proposed essentially what the OP proposed, but no DIP was
ever created for it, and it's never happened. It probably would stand a
decent chance of making it through though, since it solves a real problem,
and Andrei has previously shown interest in this solution.

- Jonathan M Davis



More information about the Digitalmars-d mailing list