gpt4 book ai didi

c++ - 为什么 std::bind 在将 icc 14.01 与 gcc 4.8 一起使用时会出错?

转载 作者:行者123 更新时间:2023-11-30 04:09:09 24 4
gpt4 key购买 nike

我在编译这段短代码时遇到了问题:

更新:我有一个更简单的代码片段现在会产生相同的错误,旧的代码片段仍然可以在帖子末尾看到。

#include <vector>
#include <iostream>
#include <functional>

class Bar {

public:
void foo(double x, double y) {
std::cout << x << std::endl;
std::cout << y << std::endl;
}

void foo2(double x) {
using namespace std::placeholders;
auto function = std::bind(&Bar::foo, this, x, _1);
function(3);
}

};

int main(int argc, char **argv) {
Bar bar;
bar.foo2(3);
}

我有一台电脑可以正常编译:

openSUSE 12.3 with gcc 4.7.2 20130108, icc 14.0.1 20131008, boost 1_49

在这台电脑上

g++ main.cpp -std=c++11

icc main.cpp -std=c++11

工作。

在另一台电脑上

openSUSE 13.1 with gcc 4.8.1 20130909 , icc 14.0.1 20131008, boost 1_54


g++ main.cpp -std=c++11

有效,但是

icc main.cpp -std=c++11 

导致以下错误消息:

main2.cpp(17): error: no instance of overloaded function "std::_Bind<_Functor (_Bound_args...)>::operator() [with _Functor=std::_Mem_fn<double (Bar::*)(double, double)>, _Bound_args=<Bar *, double, std::_Placeholder<1>>]" matches the argument list
argument types are: (int)
object type is: std::_Bind<std::_Mem_fn<double (Bar::*)(double, double)> (Bar *, double, std::_Placeholder<1>)>
function(3);

旧代码:

#include <vector>

#include "boost/numeric/odeint/stepper/runge_kutta4.hpp"

using namespace boost::numeric::odeint;
typedef std::vector<double> state_type;

class Right_Hand_Side {
public:
void operator()(const state_type &y, state_type &y_dot, const double t)
{}

};

int main(int argc, char **argv) {

Right_Hand_Side right_hand_side;
std::vector<double> state(10);
runge_kutta4<state_type> stepper;
stepper.do_step( std::ref(right_hand_side), state, 0, 0.1);

}

错误信息:

XXX/include/boost/numeric/odeint/util/resizer.hpp(72): error: no instance of overloaded function "std::_Bind<_Functor (_Bound_args...)>::operator() [with _Functor=std::_Mem_fn<bool (boost::numeric::odeint::explicit_stepper_base<boost::numeric::odeint::explicit_generic_rk<4UL, 4UL, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>, (unsigned short)4U,
state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>::*)(const std::vector<double, std::allocator<double>> &)>, _Bound_args=<std::reference_wrapper<boost::numeric::odeint::explicit_stepper_base<boost::numeric::odeint::explicit_generic_rk<4UL, 4UL, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations,
boost::numeric::odeint::initially_resizer>, (unsigned short)4U, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>>, std::_Placeholder<1>>]" matches the argument list
argument types are: (const std::vector<double, std::allocator<double>>)
object type is: std::_Bind<std::_Mem_fn<bool (boost::numeric::odeint::explicit_stepper_base<boost::numeric::odeint::explicit_generic_rk<4UL, 4UL, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>, (unsigned short)4U, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations,
boost::numeric::odeint::initially_resizer>::*)(const std::vector<double, std::allocator<double>> &)> (std::reference_wrapper<boost::numeric::odeint::explicit_stepper_base<boost::numeric::odeint::explicit_generic_rk<4UL, 4UL, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>, (unsigned short)4U, state_type, double, state_type, double,
boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>>, std::_Placeholder<1>)>
return f( x );
^
detected during:
instantiation of "bool boost::numeric::odeint::initially_resizer::adjust_size(const State &, ResizeFunction) [with State=std::vector<double, std::allocator<double>>, ResizeFunction=std::_Bind<std::_Mem_fn<bool (boost::numeric::odeint::explicit_stepper_base<boost::numeric::odeint::explicit_generic_rk<4UL, 4UL, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>, (unsigned
short)4U, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>::*)(const std::vector<double, std::allocator<double>> &)> (std::reference_wrapper<boost::numeric::odeint::explicit_stepper_base<boost::numeric::odeint::explicit_generic_rk<4UL, 4UL, state_type, double, state_type, double, boost::numeric::odeint::range_algebra,
boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>, (unsigned short)4U, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>>, std::_Placeholder<1>)>]" at line 196 of "XXX//include/boost/numeric/odeint/stepper/base/explicit_stepper_base.hpp"
instantiation of "void boost::numeric::odeint::explicit_stepper_base<Stepper, Order, State, Value, Deriv, Time, Algebra, Operations, Resizer>::do_step_v1(System, StateInOut &, boost::numeric::odeint::explicit_stepper_base<Stepper, Order, State, Value, Deriv, Time, Algebra, Operations, Resizer>::time_type, boost::numeric::odeint::explicit_stepper_base<Stepper, Order, State, Value, Deriv, Time, Algebra, Operations, Resizer>::time_type) [with
Stepper=boost::numeric::odeint::explicit_generic_rk<4UL, 4UL, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>, Order=(unsigned short)4U, State=state_type, Value=double, Deriv=state_type, Time=double, Algebra=boost::numeric::odeint::range_algebra, Operations=boost::numeric::odeint::default_operations, Resizer=boost::numeric::odeint::initially_resizer,
System=std::reference_wrapper<Right_Hand_Side>, StateInOut=std::vector<double, std::allocator<double>>]" at line 113 of "XXX//include/boost/numeric/odeint/stepper/base/explicit_stepper_base.hpp"
instantiation of "void boost::numeric::odeint::explicit_stepper_base<Stepper, Order, State, Value, Deriv, Time, Algebra, Operations, Resizer>::do_step(System, StateInOut &, boost::numeric::odeint::explicit_stepper_base<Stepper, Order, State, Value, Deriv, Time, Algebra, Operations, Resizer>::time_type, boost::numeric::odeint::explicit_stepper_base<Stepper, Order, State, Value, Deriv, Time, Algebra, Operations, Resizer>::time_type) [with
Stepper=boost::numeric::odeint::explicit_generic_rk<4UL, 4UL, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>, Order=(unsigned short)4U, State=state_type, Value=double, Deriv=state_type, Time=double, Algebra=boost::numeric::odeint::range_algebra, Operations=boost::numeric::odeint::default_operations, Resizer=boost::numeric::odeint::initially_resizer,
System=std::reference_wrapper<Right_Hand_Side>, StateInOut=std::vector<double, std::allocator<double>>]" at line 21 of "main.cpp"

XXX//include/boost/numeric/odeint/util/resizer.hpp(72): error: no instance of overloaded function "std::_Bind<_Functor (_Bound_args...)>::operator() [with _Functor=std::_Mem_fn<bool (boost::numeric::odeint::explicit_generic_rk<4UL, 4UL, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>::*)(const std::vector<double, std::allocator<double>> &)>,
_Bound_args=<std::reference_wrapper<boost::numeric::odeint::explicit_generic_rk<4UL, 4UL, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>>, std::_Placeholder<1>>]" matches the argument list
argument types are: (const std::vector<double, std::allocator<double>>)
object type is: std::_Bind<std::_Mem_fn<bool (boost::numeric::odeint::explicit_generic_rk<4UL, 4UL, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>::*)(const std::vector<double, std::allocator<double>> &)> (std::reference_wrapper<boost::numeric::odeint::explicit_generic_rk<4UL, 4UL, state_type, double, state_type, double, boost::numeric::odeint::range_algebra,
boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>>, std::_Placeholder<1>)>
return f( x );
^
detected during:
instantiation of "bool boost::numeric::odeint::initially_resizer::adjust_size(const State &, ResizeFunction) [with State=std::vector<double, std::allocator<double>>, ResizeFunction=std::_Bind<std::_Mem_fn<bool (boost::numeric::odeint::explicit_generic_rk<4UL, 4UL, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>::*)(const std::vector<double, std::allocator<double>>
&)> (std::reference_wrapper<boost::numeric::odeint::explicit_generic_rk<4UL, 4UL, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>>, std::_Placeholder<1>)>]" at line 146 of "XXX//include/boost/numeric/odeint/stepper/explicit_generic_rk.hpp"
instantiation of "void boost::numeric::odeint::explicit_generic_rk<StageCount, Order, State, Value, Deriv, Time, Algebra, Operations, Resizer>::do_step_impl(System, const StateIn &, const DerivIn &, boost::numeric::odeint::explicit_generic_rk<StageCount, Order, State, Value, Deriv, Time, Algebra, Operations, Resizer>::time_type, StateOut &, boost::numeric::odeint::explicit_generic_rk<StageCount, Order, State, Value, Deriv, Time, Algebra, Operations, Resizer>::time_type) [with
StageCount=4UL, Order=4UL, State=state_type, Value=double, Deriv=state_type, Time=double, Algebra=boost::numeric::odeint::range_algebra, Operations=boost::numeric::odeint::default_operations, Resizer=boost::numeric::odeint::initially_resizer, System=std::reference_wrapper<Right_Hand_Side>, StateIn=std::vector<double, std::allocator<double>>, DerivIn=state_type, StateOut=std::vector<double, std::allocator<double>>]" at line 198 of
"XXX//include/boost/numeric/odeint/stepper/base/explicit_stepper_base.hpp"
instantiation of "void boost::numeric::odeint::explicit_stepper_base<Stepper, Order, State, Value, Deriv, Time, Algebra, Operations, Resizer>::do_step_v1(System, StateInOut &, boost::numeric::odeint::explicit_stepper_base<Stepper, Order, State, Value, Deriv, Time, Algebra, Operations, Resizer>::time_type, boost::numeric::odeint::explicit_stepper_base<Stepper, Order, State, Value, Deriv, Time, Algebra, Operations, Resizer>::time_type) [with
Stepper=boost::numeric::odeint::explicit_generic_rk<4UL, 4UL, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>, Order=(unsigned short)4U, State=state_type, Value=double, Deriv=state_type, Time=double, Algebra=boost::numeric::odeint::range_algebra, Operations=boost::numeric::odeint::default_operations, Resizer=boost::numeric::odeint::initially_resizer,
System=std::reference_wrapper<Right_Hand_Side>, StateInOut=std::vector<double, std::allocator<double>>]" at line 113 of "XXX//include/boost/numeric/odeint/stepper/base/explicit_stepper_base.hpp"
instantiation of "void boost::numeric::odeint::explicit_stepper_base<Stepper, Order, State, Value, Deriv, Time, Algebra, Operations, Resizer>::do_step(System, StateInOut &, boost::numeric::odeint::explicit_stepper_base<Stepper, Order, State, Value, Deriv, Time, Algebra, Operations, Resizer>::time_type, boost::numeric::odeint::explicit_stepper_base<Stepper, Order, State, Value, Deriv, Time, Algebra, Operations, Resizer>::time_type) [with
Stepper=boost::numeric::odeint::explicit_generic_rk<4UL, 4UL, state_type, double, state_type, double, boost::numeric::odeint::range_algebra, boost::numeric::odeint::default_operations, boost::numeric::odeint::initially_resizer>, Order=(unsigned short)4U, State=state_type, Value=double, Deriv=state_type, Time=double, Algebra=boost::numeric::odeint::range_algebra, Operations=boost::numeric::odeint::default_operations, Resizer=boost::numeric::odeint::initially_resizer,
System=std::reference_wrapper<Right_Hand_Side>, StateInOut=std::vector<double, std::allocator<double>>]" at line 21 of "main.cpp"

compilation aborted for main.cpp (code 2)

我觉得这不是 boost::odeint 特有的,而是在使用 std::bind、std::function 等时出现的一个奇怪的编译器问题(这是真的,请参阅帖子顶部的新代码)

最佳答案

我在英特尔论坛上发布了这个问题 here并得到以下响应:

Thanks for reporting it!

We've been working on it and it's been tracked as DPD200242895. Will update you when the fix is available. There is no easy workaround for this. Sorry about that.

看来他们已经意识到这个问题并正在研究解决方案。希望下一次更新/发布能解决这个问题。

更新:

此问题已在版本 14.0 update 3 及更高版本中修复:

This issue is fixed in 14.0 update 3 and later, as well as 15.0.

Thanks,Jennifer

关于c++ - 为什么 std::bind 在将 icc 14.01 与 gcc 4.8 一起使用时会出错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21453232/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com