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++:
  1. void increment(int &i)
  2. {
  3.     ++i;
  4. }
  5.  
  6. static void test1()
  7. {
  8.     boost::function<void (int &)> add1=::increment;
  9.     std::vector<std::vector<int>> vec(10, std::vector<int>(10, 2010));
  10.     std::for_each(vec.begin(), vec.end(), boost::lambda::bind(boost::lambda::ll::for_each(),
  11.                 boost::lambda::bind(boost::mem_fn((std::vector<int>::iterator(std::vector<int>::*)())
  12.                         &std::vector<int>::begin), boost::lambda::_1),
  13.                 boost::lambda::bind(boost::mem_fn((std::vector<int>::iterator(std::vector<int>::*)())
  14.                         &std::vector<int>::end), boost::lambda::_1),
  15.                 add1));
  16.     std::for_each(vec.begin(), vec.end(), boost::lambda::bind(boost::lambda::ll::copy(),
  17.                 boost::lambda::bind(boost::mem_fn((std::vector<int>::iterator(std::vector<int>::*)())
  18.                         &std::vector<int>::begin), boost::lambda::_1),
  19.                 boost::lambda::bind(boost::mem_fn((std::vector<int>::iterator(std::vector<int>::*)())
  20.                         &std::vector<int>::end), boost::lambda::_1),
  21.                 std::ostream_iterator<int>(std::cout, " ")));
  22.     std::cin.get();
  23. }

3 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!

  3. nooga says:

    Been done. C++ templates – the worst notation for lambda calculus on earth.

Leave a Reply

Designed by SirMike © All rights reserved

Valid XHTML 1.0! Valid CSS!

Powered by Rootnode