What's everybody's opinion on using lambdas to do nested functions in C++? For example, instead of this:

static void prepare_eggs()
{
   ...
}

static void prepare_ham()
{
   ...
}

static void prepare_cheese()
{
   ...
}

static fry_ingredients()
{
   ...
}

void make_omlette()
{
    prepare_eggs();
    prepare_ham();
    prepare_cheese();
    fry_ingredients();
}

You do this:

void make_omlette()
{
    auto prepare_eggs = [&]()
    {
       ...
    };

    auto prepare_ham = [&]()
    {
       ...
    };

    auto prepare_cheese = [&]()
    {
       ...
    };

    auto fry_ingredients = [&]()
    {
       ...
    };


    prepare_eggs();
    prepare_ham();
    prepare_cheese();
    fry_ingredients();
}

Having come from the generation that learned how to code by using Pascal, nested functions make perfect sense to me. However, this usage seemed to confuse some of the less experienced developers in my group at work during a code review where I made use of lambdas in this way.

Edit
Report