C++ 移植C++;11 std::thread to boost::thread编译问题
我正在尝试使用boost::thread将C++11 std::thread代码移植到VC9(VS2008)。下面的“等效”C++11代码在msvc12上编译得很好:C++ 移植C++;11 std::thread to boost::thread编译问题,c++,visual-c++,boost,boost-thread,boost-move,C++,Visual C++,Boost,Boost Thread,Boost Move,我正在尝试使用boost::thread将C++11 std::thread代码移植到VC9(VS2008)。下面的“等效”C++11代码在msvc12上编译得很好: #include <iostream> #include <thread> #include <vector> #include <algorithm> #include <cassert> void thFun(int i) { std::cout <
#include <iostream>
#include <thread>
#include <vector>
#include <algorithm>
#include <cassert>
void thFun(int i)
{
std::cout << "Hello from thread " << i << " !\n";
}
int main()
{
std::vector<std::thread> workers;
for (int i = 0; i < 10; ++i)
{
auto th = std::thread(&thFun, i);
workers.push_back(std::move(th));
assert(!th.joinable());
}
std::cout << "Hello from main!\n";
std::for_each(workers.begin(), workers.end(), [](std::thread& th)
{
assert(th.joinable());
th.join();
});
return 0;
}
#包括
#包括
#包括
#包括
#包括
虚无乐趣(国际一)
{
std::cout将此放在开头:
#define BOOST_THREAD_USES_MOVE
请参阅以获取参考。它启用Boost.Move(Boost::Move
)为Boost::thread
提供的仿真,该仿真在Boost.thread版本2中默认禁用(MSVC9可能在您的情况下使用).这是完整的错误消息吗?错误出现在源代码的哪一行?可能与此有关。您是否尝试过替换BOOST\u AUTO
?在包含任何BOOST头之前,请尝试以下操作:\define BOOST\u THREAD\u USES\u MOVE
。请参阅以获取参考。@Albert在中编辑的完整消息。错误出现在第19行BOOST::container::vector workers
但实际错误在第23行workers上。向后推(boost::move(th))
使用#定义boost_线程_使用_move工作。现在在vc9中正确编译。
d:\program data\boost\boost_1_55_0\boost\preprocessor\iteration\detail\local.hpp(37): error C2770: invalid explicit template argument(s) for '::boost::move_detail::enable_if_c<boost::enable_move_utility_emulation<T>::value&&!boost::move_detail::is_rv<T>::value,const T&>::type boost::forward(const ::boost::move_detail::identity<T>::type &)'
d:\program data\boost\boost_1_55_0\boost\move\utility.hpp(78) : see declaration of 'boost::forward'
d:\program data\boost\boost_1_55_0\boost\container\vector.hpp(1797) : see reference to function template instantiation 'void boost::container::allocator_traits<Alloc>::construct<T,T>(Alloc &,T *,const P0 &)' being compiled
with
[
Alloc=std::allocator<boost::thread>,
T=boost::thread,
P0=boost::thread
]
d:\program data\boost\boost_1_55_0\boost\container\vector.hpp(1791) : while compiling class template member function 'void boost::container::vector<T>::priv_push_back(const T &)'
with
[
T=boost::thread
]
d:\work\boostthreadscratch\boostthreadscratch\boostthreadscratch.cpp(19) : see reference to class template instantiation 'boost::container::vector<T>' being compiled
with
[
T=boost::thread
]
#define BOOST_THREAD_USES_MOVE