Vomit C++

November 17th, 2007

Few days ago I found very interesting piece of code in polish usenet. The code is correct and it works fine but it looks like... yes, like vomit. C++ programmers, can I have a request? Please, do not move features from other languages that we can live without, to the C++.

C++:
void increment(int &i)
{
    ++i;
}

static void test1()
{
    boost::function<void (int &)> add1=::increment;
    std::vector<std::vector<int>> vec(10, std::vector<int>(10, 2010));
    std::for_each(vec.begin(), vec.end(), boost::lambda::bind(boost::lambda::ll::for_each(),
                boost::lambda::bind(boost::mem_fn((std::vector<int>::iterator(std::vector<int>::*)())
                        &std::vector<int>::begin), boost::lambda::_1),
                boost::lambda::bind(boost::mem_fn((std::vector<int>::iterator(std::vector<int>::*)())
                        &std::vector<int>::end), boost::lambda::_1),
                add1));
    std::for_each(vec.begin(), vec.end(), boost::lambda::bind(boost::lambda::ll::copy(),
                boost::lambda::bind(boost::mem_fn((std::vector<int>::iterator(std::vector<int>::*)())
                        &std::vector<int>::begin), boost::lambda::_1),
                boost::lambda::bind(boost::mem_fn((std::vector<int>::iterator(std::vector<int>::*)())
                        &std::vector<int>::end), boost::lambda::_1),
                std::ostream_iterator<int>(std::cout, " ")));
    std::cin.get();
}

2 Responses to “Vomit C++”

  1. Xion Says:

    Hey, that’s only about 4 times more code than ordinary loop that does the incrementation and printing - don’t judge it too harshly ;D

  2. Jimmy Bogard Says:

    Someone reaaaaaally wants to make C++ do functional programming. Here’s an idea, don’t use a hammer on a screw! Use a screwdriver!

Leave a Reply

Designed by SirMike © All rights reserved

Valid XHTML 1.0! Valid CSS!