automatic function call after closing block

Saaa empty at needmail.com
Sat Sep 20 10:48:28 PDT 2008


:D
Looks cool!
No way I could have come up with that.
Same question (as I have no clue how this internally works):
Is there a performance penalty?

> How about a horrible/wonderful misuse of the 'in' operator?  (credited
> to Tom S):
>
> class Texture
> {
> ...
>    struct BindBlock
>    {
>        Texture self;
>        void opIn(void delegate() dg)
>        {
>            self.bind();
>            scope(exit) self.unbind();
>            dg();
>        }
>    }
>
>    BindBlock bindBlock() { return BindBlock(this); }
> ...
> }
>
> auto t = new Texture("foo.png");
>
> t.bindBlock() in
> {
>    // some rendering code!
> };
>
>
> It has a nice functional-sounding flair to it, with the 'in' there ;) 




More information about the Digitalmars-d-learn mailing list