2010-01-14 46 views
1

爲什麼這個boost :: lambda表達式不起作用?這個boost :: lambda使用有什麼問題?

boost::function<bool (boost::uint64_t, boost::uint64_t&, unsigned int, float)> myFunct = boost::lambda::_3 < 1; 

我得到了這些編譯錯誤,這可能不會有幫助,因爲它們真的很神祕。

|| In file included from /usr/include/boost/function/detail/maybe_include.hpp:33, 
||     from /usr/include/boost/function/detail/function_iterate.hpp:14, 
||     from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:67, 
||     from /usr/include/boost/function.hpp:64, 
||     from CMoteurRecherche.hpp:13, 
||     from CBenchmark.hpp:4, 
||     from CBenchmark.cpp:1: 
|| /usr/include/boost/function/function_template.hpp: In static member function 'static R boost::detail::function::function_obj_invoker4<FunctionObj, R, T0, T1, T2, T3>::invoke(boost::detail::function::function_buffer&, T0, T1, T2, T3) [with FunctionObj = boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::explicit_return_type_action<bool>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::relational_action<boost::lambda::less_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<4> >, const int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples:: 
|| null_type, boost::tuples::null_type> > >, R = bool, T0 = long unsigned int, T1 = uint64_t&, T2 = unsigned int, T3 = float]': 
/usr/include/boost/function/function_template.hpp|904| instantiated from 'void boost::function4<R, T1, T2, T3, T4>::assign_to(Functor) [with Functor = boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::explicit_return_type_action<bool>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::relational_action<boost::lambda::less_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<4> >, const int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > >, R = bool, T0 = long unsigned int, T1 = uint64_t&, T2 = uns 
|| igned int, T3 = float]' 
/usr/include/boost/function/function_template.hpp|720| instantiated from 'boost::function4<R, T1, T2, T3, T4>::function4(Functor, typename boost::enable_if_c<boost::type_traits::ice_not::value, int>::type) [with Functor = boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::explicit_return_type_action<bool>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::relational_action<boost::lambda::less_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<4> >, const int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::nul 
|| l_type> > >, R = bool, T0 = long unsigned int, T1 = uint64_t&, T2 = unsigned int, T3 = float]' 
/usr/include/boost/function/function_template.hpp|1040| instantiated from 'boost::function<R(T0, T1, T2, T3)>::function(Functor, typename boost::enable_if_c<boost::type_traits::ice_not::value, int>::type) [with Functor = boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::explicit_return_type_action<bool>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::relational_action<boost::lambda::less_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<4> >, const int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null 
|| _type> > >, R = bool, T0 = uint64_t, T1 = uint64_t&, T2 = unsigned int, T3 = float]' 
/usr/include/boost/function/function_template.hpp|1081| instantiated from 'typename boost::enable_if_c<boost::type_traits::ice_not::value, boost::function<R(T0, T1, T2, T3)>&>::type boost::function<R(T0, T1, T2, T3)>::operator=(Functor) [with Functor = boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::explicit_return_type_action<bool>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::relational_action<boost::lambda::less_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<4> >, const int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples 
|| ::null_type, boost::tuples::null_type> > >, R = bool, T0 = uint64_t, T1 = uint64_t&, T2 = unsigned int, T3 = float]' 
/home/mathmoi/MatMoi/CBenchmark.cpp|85| instantiated from here 
/usr/include/boost/function/function_template.hpp|131| error: no match for call to '(boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::explicit_return_type_action<bool>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::relational_action<boost::lambda::less_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<4> >, const int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > >) (long unsigned int&, long unsigned int&, unsigned int&, float&)' 
/usr/include/boost/lambda/detail/lambda_functors.hpp|137| note: candidates are: typename T::sig<boost::tuples::null_type>::type boost::lambda::lambda_functor<Base>::operator()() const [with T = boost::lambda::lambda_functor_base<boost::lambda::explicit_return_type_action<bool>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::relational_action<boost::lambda::less_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<4> >, const int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> >] 
+6

我很高興我不用C++編碼:) – Skilldrick 2010-01-14 14:01:35

回答

3

我認爲答案來自Boost.Lambda參考:

在lambda 表達式中使用佔位符確定 所得函數是無,一元,二元 或3元。最高的 佔位符指數是決定性的。

您的最高佔位符是_3,但該函數需要4個參數。不幸的是,從引用看來,佔位符最多隻能提供3個參數。

順便說一句,如果函數了3個參數,它似乎有可能使用逗號操作符,以顯示功能的元數(結果被丟棄):

boost::function<bool(int, int, int)> f = boost::lambda::_2 < 1; //error 
boost::function<bool(int, int, int)> f = (boost::lambda::_3, boost::lambda::_2 < 1); //OK 
+0

恩,看起來你是對的。我並不知道這個限制。謝謝。 – 2010-01-14 14:15:45