2012-03-29 1 views
1

Этот код компилируется нормально с GCC и Clang, но не с MSVC 2010:MSVC и повышение :: лямбда :: Ошибка привязки: T0: Стандарт-argment не допускается

#include <boost/lambda/lambda.hpp> 
#include <boost/lambda/bind.hpp> 
#include <boost/function.hpp> 
#include <list> 
#include <string> 

enum Actions {}; 
std::string eventStart(size_t index, Actions action, std::list<std::string> const& = std::list<std::string>()) { return ""; } 

static void test() { 
    using namespace boost::lambda; 
    size_t i = 0; 
    int action = 0; 
    boost::function<std::string (std::list<std::string> const&)> startF = bind(eventStart, i, (Actions)action, _1); 
} 

выдает ошибку:

1>c:\users\albert zeyer\documents\visual studio 2010\projects\test\test\test2.cpp(14): error C2383: 'T0': Für dieses Symbol sind Standardargumente nicht zulässig 
1>   c:\users\albert zeyer\documents\visual studio 2010\projects\test\test\test2.cpp(14): Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "boost::lambda::detail::bind_tuple_mapper<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9>". 
1>   with 
1>   [ 
1>    T0=std::string (size_t,Actions,const std::list<std::string> &), 
1>    T1=const size_t, 
1>    T2=const Actions, 
1>    T3=boost::lambda::placeholder1_type, 
1>    T4=boost::tuples::null_type, 
1>    T5=boost::tuples::null_type, 
1>    T6=boost::tuples::null_type, 
1>    T7=boost::tuples::null_type, 
1>    T8=boost::tuples::null_type, 
1>    T9=boost::tuples::null_type 
1>   ] 
1>c:\users\albert zeyer\documents\visual studio 2010\projects\test\test\test2.cpp(14): error C2383: 'Arg1': Für dieses Symbol sind Standardargumente nicht zulässig 

(по теме: как я могу получить ошибку на английском языке?)

Использование &eventStart вместо также не работает, но ошибка отличается:

1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xxcallfun(7): error C2664: 'std::string (size_t,Actions,const std::list<_Ty> &)': Konvertierung des Parameters 3 von 'const boost::lambda::placeholder1_type' in 'const std::list<_Ty> &' nicht möglich 
1>   with 
1>   [ 
1>    _Ty=std::string 
1>   ] 
1>   Ursache: Konvertierung von 'const boost::lambda::placeholder1_type' in 'const std::list<_Ty>' nicht möglich 
1>   with 
1>   [ 
1>    _Ty=std::string 
1>   ] 
1>   Kein benutzerdefinierter Konvertierungsoperator verfügbar, der diese Konvertierung durchführen kann, oder der Operator kann nicht aufgerufen werden 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\xxbind1(292): Siehe Verweis auf die Instanziierung der gerade kompilierten Funktions-template "_Ret std::tr1::_Callable_fun<_Ty,_Indirect>::_ApplyX<_Ret,_Arg&,Actions&,boost::lambda::lambda_functor<T>&>(_Arg0,_Arg1,_Arg2) const". 
1>   with 
1>   [ 
1>    _Ret=_Rx, 
1>    _Ty=std::string (__cdecl *const)(size_t,Actions,const std::list<std::string> &), 
1>    _Indirect=false, 
1>    _Arg=size_t, 
1>    T=boost::lambda::placeholder<1>, 
1>    _Arg0=size_t &, 
1>    _Arg1=Actions &, 
1>    _Arg2=const boost::lambda::placeholder1_type & 
1>   ] 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\xxbind0(31): Siehe Verweis auf die Instanziierung der gerade kompilierten Funktions-template "_Ret std::tr1::_Bind3<_Callable,_Arg0,_Arg1,_Arg2>::_ApplyX<_Rx,const std::list<_Ty>&,std::tr1::_Nil&,std::tr1::_Nil&,std::tr1::_Nil&,std::tr1::_Nil&,std::tr1::_Nil&,std::tr1::_Nil&,std::tr1::_Nil&,std::tr1::_Nil&,std::tr1::_Nil&>(_Barg0,_Barg1,_Barg2,_Barg3,_Barg4,_Barg5,_Barg6,_Barg7,_Barg8,_Barg9)". 
1>   with 
1>   [ 
1>    _Ret=_Rx, 
1>    _Callable=std::tr1::_Callable_fun<std::string (__cdecl *const)(size_t,Actions,const std::list<std::string> &),false>, 
1>    _Arg0=size_t, 
1>    _Arg1=Actions, 
1>    _Arg2=const boost::lambda::placeholder1_type, 
1>    _Ty=std::string, 
1>    _Barg0=const std::list<std::string> &, 
1>    _Barg1=std::tr1::_Nil &, 
1>    _Barg2=std::tr1::_Nil &, 
1>    _Barg3=std::tr1::_Nil &, 
1>    _Barg4=std::tr1::_Nil &, 
1>    _Barg5=std::tr1::_Nil &, 
1>    _Barg6=std::tr1::_Nil &, 
1>    _Barg7=std::tr1::_Nil &, 
1>    _Barg8=std::tr1::_Nil &, 
1>    _Barg9=std::tr1::_Nil & 
1>   ] 
1>   c:\program files (x86)\boost\boost_1_47\boost\function\function_template.hpp(132): Siehe Verweis auf die Instanziierung der gerade kompilierten Funktions-template "std::basic_string<_Elem,_Traits,_Ax> std::tr1::_Bind_base<_Ret,_BindN>::operator()<const std::list<_Ty>&>(_Carg0)". 
1>   with 
1>   [ 
1>    _Elem=char, 
1>    _Traits=std::char_traits<char>, 
1>    _Ax=std::allocator<char>, 
1>    _Ret=std::string, 
1>    _BindN=std::tr1::_Bind3<std::tr1::_Callable_fun<std::string (__cdecl *const)(size_t,Actions,const std::list<std::string> &),false>,size_t,Actions,const boost::lambda::placeholder1_type>, 
1>    _Ty=std::string, 
1>    _Carg0=const std::list<std::string> & 
1>   ] 
1>   c:\program files (x86)\boost\boost_1_47\boost\function\function_template.hpp(126): Bei der Kompilierung der Klassen-template der std::string boost::detail::function::function_obj_invoker1<FunctionObj,R,T0>::invoke(boost::detail::function::function_buffer &,T0)-Memberfunktion 
1>   with 
1>   [ 
1>    FunctionObj=std::tr1::_Bind<std::string,std::string,std::tr1::_Bind3<std::tr1::_Callable_fun<std::string (__cdecl *const)(size_t,Actions,const std::list<std::string> &),false>,size_t,Actions,const boost::lambda::placeholder1_type>>, 
1>    R=std::string, 
1>    T0=const std::list<std::string> 
1>   ] 
1>   c:\program files (x86)\boost\boost_1_47\boost\function\function_template.hpp(907): Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "boost::detail::function::function_obj_invoker1<FunctionObj,R,T0>". 
1>   with 
1>   [ 
1>    FunctionObj=std::tr1::_Bind<std::string,std::string,std::tr1::_Bind3<std::tr1::_Callable_fun<std::string (__cdecl *const)(size_t,Actions,const std::list<std::string> &),false>,size_t,Actions,const boost::lambda::placeholder1_type>>, 
1>    R=std::string, 
1>    T0=const std::list<std::string> 
1>   ] 
1>   c:\program files (x86)\boost\boost_1_47\boost\function\function_template.hpp(722): Siehe Verweis auf die Instanziierung der gerade kompilierten Funktions-template "void boost::function1<R,T0>::assign_to<Functor>(Functor)". 
1>   with 
1>   [ 
1>    R=std::string, 
1>    T0=const std::list<std::string> , 
1>    Functor=std::tr1::_Bind<std::string,std::string,std::tr1::_Bind3<std::tr1::_Callable_fun<std::string (__cdecl *const)(size_t,Actions,const std::list<std::string> &),false>,size_t,Actions,const boost::lambda::placeholder1_type>> 
1>   ] 
1>   c:\program files (x86)\boost\boost_1_47\boost\function\function_template.hpp(1043): Siehe Verweis auf die Instanziierung der gerade kompilierten Funktions-template "boost::function1<R,T0>::function1<std::tr1::_Bind<_Result_type,_Ret,_BindN>>(Functor,int)". 
1>   with 
1>   [ 
1>    R=std::string, 
1>    T0=const std::list<std::string> , 
1>    _Result_type=std::string, 
1>    _Ret=std::string, 
1>    _BindN=std::tr1::_Bind3<std::tr1::_Callable_fun<std::string (__cdecl *const)(size_t,Actions,const std::list<std::string> &),false>,size_t,Actions,const boost::lambda::placeholder1_type>, 
1>    Functor=std::tr1::_Bind<std::string,std::string,std::tr1::_Bind3<std::tr1::_Callable_fun<std::string (__cdecl *const)(size_t,Actions,const std::list<std::string> &),false>,size_t,Actions,const boost::lambda::placeholder1_type>> 
1>   ] 
1>   c:\users\albert zeyer\documents\visual studio 2010\projects\test\test\test2.cpp(14): Siehe Verweis auf die Instanziierung der gerade kompilierten Funktions-template "boost::function<Signature>::function<std::tr1::_Bind<_Result_type,_Ret,_BindN>>(Functor,int)". 
1>   with 
1>   [ 
1>    Signature=std::string (const std::list<std::string> &), 
1>    _Result_type=std::string, 
1>    _Ret=std::string, 
1>    _BindN=std::tr1::_Bind3<std::tr1::_Callable_fun<std::string (__cdecl *const)(size_t,Actions,const std::list<std::string> &),false>,size_t,Actions,const boost::lambda::placeholder1_type>, 
1>    Functor=std::tr1::_Bind<std::string,std::string,std::tr1::_Bind3<std::tr1::_Callable_fun<std::string (__cdecl *const)(size_t,Actions,const std::list<std::string> &),false>,size_t,Actions,const boost::lambda::placeholder1_type>> 
1>   ] 

Почему? Код кажется правильным.

Он работает, когда я удаляю аргумент по умолчанию для функции eventStart.

+0

Тривиальное обходное решение состоит в том, чтобы выполнить 'bind (& eventStart, ...)', а не 'bind (eventStart, ...)', но я не знаю, почему это необходимо (или если это необходимо вообще совместимый компилятор). Кроме того, вы должны использовать [Boost.Phoenix] (http://www.boost.org/libs/phoenix/), а не Boost.Lambda для нового кода, так как последний считается официально устаревшим в пользу первого. – ildjarn

+0

@ildjarn: Также не работает. Я обновил вопрос. – Albert

+0

Он работает для меня, тестируя VC++ 2010 SP1 и Boost 1.49.0. – ildjarn

ответ

1

Как предложено ildjarn, я использую &eventStart вместо eventStart. Только это еще не работало для меня.

Но когда я меняю bind на boost::lambda::bind, это работает.

Странно, однако, что нет using namespace std; или около того.

+0

Это не исправляет его для меня. –

+0

@MichaelBurr: Хм, интересно. Точно такой же тестовый код из моего вопроса? А также использовать '& eventStart' вместо' eventStart'. Какую версию MSVC вы используете? – Albert

+0

если я использую * оба * 'boost :: lambda :: bind' и' & eventStart' компилирует. Наверное, я раньше этого не делал. Я запускаю VS2010 SP1 (10.0.40219.1 SP1Rel), у которого есть версия cl.exe 16.00.40219.01. –