Function increase and increase lambda

I saw several related questions, but I'm still just puzzled. What is wrong with this syntax:

boost::function<int (int)> g = f; boost::function<int (int)> g2 = 2*g(boost::lambda::_1); 

I tried it with a boost of 1.35 and 1.38 (these are the two installations that I lay) on gcc 4.3.4, and both of them give error variations:

 no match for call to '(boost::function<int ()(int)>) (const boost::lambda::lambda_functor<boost::lambda::placeholder<1> >&)' 
+4
source share
2 answers

You cannot directly call a function using a placeholder. You must use bind .

 boost::function<int (int)> g2 = 2 * boost::lambda::bind(g, boost::lambda::_1); 

( Example )

+8
source

I suggest you abandon Boost.Lambda as deprecated. A compiler that supports C ++ 0x provides a native lambda and is easier to understand. You can use GCC with version 4.4 or later, Visual Studio 2010 also supports C ++ 0x.

+2
source

Source: https://habr.com/ru/post/1338918/


All Articles