Yet another FizzBuzz Since today is apparently a good day for...unlikely FizzBuzz implementations, I decided to contribute another, this one in C++:

#include &lt;iostream&gt;
#include &lt;functional&gt;
#include &lt;vector&gt;
#include "xrange.h"

int main() {
    std::vector&lt;std::function&lt;void(int)&gt; &gt; funcs {
        [](int i) { std::cout &lt;&lt; i &lt;&lt; "\n"; },
        [](int i) { std::cout &lt;&lt; "fizz\n";  },
        [](int i) { std::cout &lt;&lt; "buzz\n";  },
        [](int i) { std::cout &lt;&lt; "fizzbuzz\n"; }
    };

    auto test = [](int i){return (i % 3 == 0) + 2 * (i % 5 == 0); };

    for (auto i : xrange(1, 101))
        funcs[test(i)](i);
}


This uses the same xrange I posted in a previous answer.

I'd be particularly interested in eliminating having to use test, but a sequence like: [[ is parsed as introducing an attribute rather than using the return from a lambda as an index (and inserting white space doesn't seem to help). I could use .at() instead, but that imposes runtime overhead I'd also rather avoid.
I'd be inclined to make a simple fixed array instead of a std::vector for funcs:

const std::function&lt;void(int i)&gt; funcs[] {
    [](int i) { std::cout &lt;&lt; i &lt;&lt; "\n"; },
    [](int ) { std::cout &lt;&lt; "fizz\n";  },
    [](int ) { std::cout &lt;&lt; "buzz\n";  },
    [](int ) { std::cout &lt;&lt; "fizzbuzz\n"; }
};


This is useful because it eliminates the overhead of memory allocations for a std::vector and the calls for constructor and destructor.  As an embedded systems guy, I tend to think about whether code can be in ROM rather than RAM, and whether work can be done at compile-time rather than run-time.

Note, too that I've omitted the variable name for the last three lambdas.  There's no real difference except that it prevents the compiler from generating a warning about "unused parameter i" in those three lines.

Also, I think you're overthinking the lambda.  The test lambda isn't really necessary at all since you can call it like this:

funcs[ (i % 3 == 0) + 2 * (i % 5 == 0) ](i);


So (without xrange.h, although one could use that also) it would look like this:

#include &lt;iostream&gt;
#include &lt;functional&gt;

int main() {
    const std::function&lt;void(int i)&gt; funcs[] {
        [](int i) { std::cout &lt;&lt; i &lt;&lt; "\n"; },
        [](int ) { std::cout &lt;&lt; "fizz\n";  },
        [](int ) { std::cout &lt;&lt; "buzz\n";  },
        [](int ) { std::cout &lt;&lt; "fizzbuzz\n"; }
    };

    for (int i=1; i &lt;= 100; ++i)
        funcs[ (i % 3 == 0) + 2 * (i % 5 == 0) ](i);
}