Challenge: write a reference counted slice that works as much as possible like a built-in slice
Tejas
notrealemail at gmail.com
Tue Dec 14 12:41:23 UTC 2021
On Tuesday, 14 December 2021 at 12:25:30 UTC, Stanislav Blinov
wrote:
> On Tuesday, 14 December 2021 at 12:14:52 UTC, Tejas wrote:
>> On Thursday, 11 November 2021 at 09:24:17 UTC, Atila Neves
>> wrote:
>
>>> `@disable this();`, but you knew that. It's true that
>>> requiring a programmer to do something to prevent bugs is a
>>> terrible idea. Sigh.
>>
>> Sorry for reviving this thread, was just sifting through...
>> The following code also outputs `dtor!`, unfortunately :(
>>
>> ```d
>>
>> import std.stdio:writeln;
>>
>> struct S{
>> @disable this();
>> ~this(){
>> writeln("dtor!");
>> }
>> }
>>
>> void main(){
>> S s = void;
>> }
>>
>> ```
>
>
> Why is this unfortunate? You void-initialize, it's on you now
> to ensure valid state, i.e. it's exactly the tongue-in-cheek
> "terrible idea" of Atila's ;)
>
> Slap a @safe on that and it won't compile.
That's what I did after reading your message, with the bonus of
slapping @safe on `S.__dtor` as well ;)
```d
import std.stdio:writeln;
struct S{
@disable this();
~this()@safe/*now @safe*/{
writeln("dtor!");
}
}
void main()@safe/* now @safe*/{
S s = void;
}
```
It defeated `@safe` ;_;
More information about the Digitalmars-d
mailing list