2014-09-20 171 views
1

我使用boost 1.56頭一個簡單的程序:不能轉換的boost ::拉姆達:: ...爲long long unsigned int類型

#include <boost/lambda/lambda.hpp> 
#include <boost/lambda/bind.hpp> 
#include <algorithm> 
#include <iostream> 

int main(int argc, char* args[]) 
{ 
    size_t a[] = { 1, 2, 3, 4 }; 
    size_t b[] = { 5, 6, 7, 8 }; 
    std::transform(a, a+4, b, a, (boost::lambda::_1 + boost::lambda::_2)); 
    for (int i=0; i<4; ++i) 
    std::cout << a[i] << ", "; 
    std::cout << std::endl; 

    return 0; 
} 

經G ++編譯 - 4.9.1在Debian Linux和運行很好,都適用於32位和64位體系結構。

另外i686-w64-mingw32-g ++(4.9.1)交叉編譯並運行正常。

然而x86_64的-W64-的mingw32-G ++(4.9.1)沒有交叉編譯64位架構是這樣的:

$ x86_64-w64-mingw32-g++ -I/opt/win64/include transform.cpp -static 
In file included from /usr/lib/gcc/x86_64-w64-mingw32/4.9-win32/include/c++/algorithm:62:0, 
      from /opt/win64/include/boost/core/swap.hpp:25, 
      from /opt/win64/include/boost/utility/swap.hpp:15, 
      from /opt/win64/include/boost/tuple/detail/tuple_basic.hpp:40, 
      from /opt/win64/include/boost/tuple/tuple.hpp:28, 
      from /opt/win64/include/boost/lambda/core.hpp:28, 
      from /opt/win64/include/boost/lambda/lambda.hpp:14, 
      from transform.cpp:1: 
/usr/lib/gcc/x86_64-w64-mingw32/4.9-win32/include/c++/bits/stl_algo.h: In instantiation of ‘_OIter std::transform(_IIter1, _IIter1, _IIter2, _OIter, _BinaryOperation) [with _IIter1 = long long unsigned int*; _IIter2 = long long unsigned int*; _OIter = long long unsigned int*; _BinaryOperation = boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::arithmetic_action<boost::lambda::plus_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<1> >, boost::lambda::lambda_functor<boost::lambda::placeholder<2> >, 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> > >]’: 
transform.cpp:11:92: required from here 
/usr/lib/gcc/x86_64-w64-mingw32/4.9-win32/include/c++/bits/stl_algo.h:4202:12: error: cannot convert ‘boost::lambda::lambda_functor_base<boost::lambda::arithmetic_action<boost::lambda::plus_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<1> >, boost::lambda::lambda_functor<boost::lambda::placeholder<2> >, 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> >::sig<boost::tuples::tuple<long long unsigned int&, long long unsigned 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> >::type {aka boost::lambda::detail::return_type_deduction_failure<boost::lambda::detail::return_type_2_arithmetic_phase_3<long long unsigned int, long long unsigned int> >}’ to ‘long long unsigned int’ in assignment 
    *__result = __binary_op(*__first1, *__first2); 
      ^
In file included from /opt/win64/include/boost/lambda/lambda.hpp:22:0, 
       from transform.cpp:1: 
/opt/win64/include/boost/lambda/detail/operator_lambda_func_base.hpp: In instantiation of ‘RET boost::lambda::lambda_functor_base<boost::lambda::arithmetic_action<boost::lambda::plus_action>, Args>::call(A&, B&, C&, Env&) const [with RET = boost::lambda::detail::return_type_deduction_failure<boost::lambda::detail::return_type_2_arithmetic_phase_3<long long unsigned int, long long unsigned int> >; A = long long unsigned int; B = long long unsigned int; C = const boost::tuples::null_type; Env = const boost::tuples::null_type; Args = boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<1> >, boost::lambda::lambda_functor<boost::lambda::placeholder<2> >, 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>]’: 
/opt/win64/include/boost/lambda/detail/lambda_functors.hpp:211:39: required from ‘typename boost::lambda::lambda_functor<Base>::inherited::sig<boost::tuples::tuple<A&, B&> >::type boost::lambda::lambda_functor<Base>::operator()(A&, B&) const [with A = long long unsigned int; B = long long unsigned int; T = boost::lambda::lambda_functor_base<boost::lambda::arithmetic_action<boost::lambda::plus_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<1> >, boost::lambda::lambda_functor<boost::lambda::placeholder<2> >, 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> >; typename boost::lambda::lambda_functor<Base>::inherited::sig<boost::tuples::tuple<A&, B&> >::type = boost::lambda::detail::return_type_deduction_failure<boost::lambda::detail::return_type_2_arithmetic_phase_3<long long unsigned int, long long unsigned int> >]’ 
/usr/lib/gcc/x86_64-w64-mingw32/4.9-win32/include/c++/bits/stl_algo.h:4202:46: required from ‘_OIter std::transform(_IIter1, _IIter1, _IIter2, _OIter, _BinaryOperation) [with _IIter1 = long long unsigned int*; _IIter2 = long long unsigned int*; _OIter = long long unsigned int*; _BinaryOperation = boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::arithmetic_action<boost::lambda::plus_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<1> >, boost::lambda::lambda_functor<boost::lambda::placeholder<2> >, 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> > >]’ 
transform.cpp:11:92: required from here 
/opt/win64/include/boost/lambda/detail/operator_lambda_func_base.hpp:160:72: error: could not convert ‘(boost::lambda::detail::select<boost::lambda::placeholder<1>, long long unsigned int, long long unsigned int, const boost::tuples::null_type, const boost::tuples::null_type>((* & boost::tuples::get<0, boost::lambda::lambda_functor<boost::lambda::placeholder<1> >, boost::tuples::cons<boost::lambda::lambda_functor<boost::lambda::placeholder<2> >, boost::tuples::null_type> >((* &((const boost::lambda::lambda_functor_base<boost::lambda::arithmetic_action<boost::lambda::plus_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<1> >, boost::lambda::lambda_functor<boost::lambda::placeholder<2> >, 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> >*)this)->boost::lambda::lambda_functor_base<boost::lambda::arithmetic_action<boost::lambda::plus_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<1> >, boost::lambda::lambda_functor<boost::lambda::placeholder<2> >, 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> >::args.boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<1> >, boost::lambda::lambda_functor<boost::lambda::placeholder<2> >, 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>::<anonymous>))), (* & a), (* & b), (* & c), (* & env)) + boost::lambda::detail::select<boost::lambda::placeholder<2>, long long unsigned int, long long unsigned int, const boost::tuples::null_type, const boost::tuples::null_type>((* & boost::tuples::get<1, boost::lambda::lambda_functor<boost::lambda::placeholder<1> >, boost::tuples::cons<boost::lambda::lambda_functor<boost::lambda::placeholder<2> >, boost::tuples::null_type> >((* &((const boost::lambda::lambda_functor_base<boost::lambda::arithmetic_action<boost::lambda::plus_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<1> >, boost::lambda::lambda_functor<boost::lambda::placeholder<2> >, 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> >*)this)->boost::lambda::lambda_functor_base<boost::lambda::arithmetic_action<boost::lambda::plus_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<1> >, boost::lambda::lambda_functor<boost::lambda::placeholder<2> >, 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> >::args.boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<1> >, boost::lambda::lambda_functor<boost::lambda::placeholder<2> >, 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>::<anonymous>))), (* & a), (* & b), (* & c), (* & env)))’ from ‘long long unsigned int’ to ‘boost::lambda::detail::return_type_deduction_failure<boost::lambda::detail::return_type_2_arithmetic_phase_3<long long unsigned int, long long unsigned int> >’ 
     detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS); \ 
                    ^
/opt/win64/include/boost/lambda/detail/operator_lambda_func_base.hpp:206:1: note: in expansion of macro ‘BOOST_LAMBDA_BINARY_ACTION’ 
BOOST_LAMBDA_BINARY_ACTION(+,arithmetic_action<plus_action>) 
^ 

呀,TL; DR

基本上出現了一些問題boost::lambda::_1 + boost::lambda::_2結合size_t(其他類型如int似乎沒問題)。

爲什麼會有問題?是一個提升的錯誤?

+1

如果您在其他平臺上使用無符號長整型數組而不是size_t會發生什麼? – 2014-09-20 00:21:46

+0

@ T.C。我得到相同的長錯誤。 – mariusm 2014-09-21 20:35:45

回答

3

這是在Coliru if the types are declared unsigned long long instead of size_t上重現的。 long long也失敗。

這看起來像一個提升中的錯誤。他們的massively complicated template machinery for operator return type deduction(很可能大部分如果沒有完全被C++ 11中的decltype所淘汰)不支持long longunsigned long long(在將它添加到C++標準之前寫得很好)。該問題僅在64位MinGW中出現size_t,因爲這是long爲32位,但size_t需要爲64位的唯一平臺,因此需要使用long long

+0

我認爲問題是找到一個操作(算術表達式)的常見/提升類型的兩個'unsigned long long'在它們的返回類型扣除內。 – dyp 2014-09-20 14:28:20