Apple Blocks added to C++?

Walter Bright newshound1 at digitalmars.com
Thu Sep 3 11:10:46 PDT 2009


Reimer Behrends wrote:
> However, you could also factor out the algorithm into a class of it's own:

Yes, so instead of a nested function with everything right there next to 
its use, I have to go elsewhere in the file looking for a class. While 
this is doable, I don't think it's half as nice. I also think that 
trying to force something that's naturally a function that simply 
accesses the outer function's variables into a class with member 
variables that have to be copied, etc., is less desirable.

I don't think you'll agree with me <g>, but take this example and 
rewrite it using classes:

    int foo(int a)
    {
          int bar(int i) { return a + 3; }

          return bar(3) + bar(4);
    }

and let's compare!



More information about the Digitalmars-d mailing list