July 21, 2010
On 07/21/2010 03:35 PM, Dmitry Olshansky wrote:
> Thanks for kind feedback (and showing some optimization tricks). Also
> this implementation still has issues with it: it calls dtor twice. Not a
> good trait for RAII technique ! :)
> Since it's now considered useful I feel myself obliged to enhance and
> correct it. Sadly enough I still haven't managed to apply an inner
> template trick.
> Here's the end result along with a simple unittest:
[snip]

The double destructor hits a bug in the compiler implementation. Anyway, here's the committed code:

http://www.dsource.org/projects/phobos/changeset/1774

It uses a new idiom that is enabled by auto returns - defines a struct inside the function and returns it. That's a veritable existential type! (http://stackoverflow.com/questions/292274/what-is-an-existential-type) I expect more of that idiom in the upcoming commits.


Andrei
July 22, 2010
On Thu, Jul 22, 2010 at 00:27, Andrei Alexandrescu < SeeWebsiteForEmail@erdani.org> wrote:

> The double destructor hits a bug in the compiler implementation. Anyway, here's the committed code:
>
> http://www.dsource.org/projects/phobos/changeset/1774
>
> It uses a new idiom that is enabled by auto returns - defines a struct inside the function and returns it. That's a veritable existential type! ( http://stackoverflow.com/questions/292274/what-is-an-existential-type) I expect more of that idiom in the upcoming commits.


Hmm, so the struct Scoped is implicitly parametrized by T and Args... Cool.

Why do you put a second layer of (Args...) in Scoped constructor? Why not
just

this(Args args) if (etc) {...}

And, in your case, if you used Args inside Scoped (which you don't do), would that be the ctor's Args which'd be used?


Philippe

PS: too bad that, if bug 2581 is not squashed, your scoped won't show in the docs :(


July 22, 2010
On 22.07.2010 2:27, Andrei Alexandrescu wrote:
> On 07/21/2010 03:35 PM, Dmitry Olshansky wrote:
>> Thanks for kind feedback (and showing some optimization tricks). Also
>> this implementation still has issues with it: it calls dtor twice. Not a
>> good trait for RAII technique ! :)
>> Since it's now considered useful I feel myself obliged to enhance and
>> correct it. Sadly enough I still haven't managed to apply an inner
>> template trick.
>> Here's the end result along with a simple unittest:
> [snip]
>
> The double destructor hits a bug in the compiler implementation. Anyway, here's the committed code:
>
> http://www.dsource.org/projects/phobos/changeset/1774
>
> It uses a new idiom that is enabled by auto returns - defines a struct inside the function and returns it. That's a veritable existential type! (http://stackoverflow.com/questions/292274/what-is-an-existential-type) I expect more of that idiom in the upcoming commits.
>
A cool idiom indeed!

I guess I should clarify the double destruction problem: it was caused by static opCall, the current implementation in Phobos does not suffers from it.

-- 
Dmitry Olshansky

July 22, 2010
Dmitry Olshansky wrote:
> On 22.07.2010 2:27, Andrei Alexandrescu wrote:
>> On 07/21/2010 03:35 PM, Dmitry Olshansky wrote:
>>> Thanks for kind feedback (and showing some optimization tricks). Also
>>> this implementation still has issues with it: it calls dtor twice. Not a
>>> good trait for RAII technique ! :)
>>> Since it's now considered useful I feel myself obliged to enhance and
>>> correct it. Sadly enough I still haven't managed to apply an inner
>>> template trick.
>>> Here's the end result along with a simple unittest:
>> [snip]
>>
>> The double destructor hits a bug in the compiler implementation. Anyway, here's the committed code:
>>
>> http://www.dsource.org/projects/phobos/changeset/1774
>>
>> It uses a new idiom that is enabled by auto returns - defines a struct inside the function and returns it. That's a veritable existential type! (http://stackoverflow.com/questions/292274/what-is-an-existential-type) I expect more of that idiom in the upcoming commits.
>>
> A cool idiom indeed!
> 
> I guess I should clarify the double destruction problem: it was caused by static opCall, the current implementation in Phobos does not suffers from it.

It doesn't, but just because it uses some heavy-handed tricks such as casting from an untyped buffer to Scoped. I found two distinct bugs by working on Scoped, which I'll submit soon.

Andrei
July 22, 2010
Philippe Sigaud wrote:
> On Thu, Jul 22, 2010 at 00:27, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org <mailto:SeeWebsiteForEmail@erdani.org>> wrote:
> 
>     The double destructor hits a bug in the compiler implementation.
>     Anyway, here's the committed code:
> 
>     http://www.dsource.org/projects/phobos/changeset/1774
> 
>     It uses a new idiom that is enabled by auto returns - defines a
>     struct inside the function and returns it. That's a veritable
>     existential type!
>     (http://stackoverflow.com/questions/292274/what-is-an-existential-type)
>     I expect more of that idiom in the upcoming commits..
> 
> 
> Hmm, so the struct Scoped is implicitly parametrized by T and Args.... Cool.
> 
> Why do you put a second layer of (Args...) in Scoped constructor? Why not just
> 
> this(Args args) if (etc) {...}
> 
> And, in your case, if you used Args inside Scoped (which you don't do), would that be the ctor's Args which'd be used?
> 
> 
> Philippe

Great point. I simplified the implementation:

http://www.dsource.org/projects/phobos/changeset/1776

> PS: too bad that, if bug 2581 is not squashed, your scoped won't show in the docs :(

I'll fix that later with a version(ddoc).


Andrei
1 2 3
Next ›   Last »