C++11 C++;标准:未来<;布尔>;在递归函数中
考虑到以下情况,是否可以递归到函数中?我认为std::move不起作用,因为在展开变量时,变量将消失,您将如何处理类似的事情C++11 C++;标准:未来<;布尔>;在递归函数中,c++11,promise,std,C++11,Promise,Std,考虑到以下情况,是否可以递归到函数中?我认为std::move不起作用,因为在展开变量时,变量将消失,您将如何处理类似的事情 auto TestFunc(std::future<bool> promisedExit , int max , const char* pszTesting) { if (promisedExit.get()) { // The calling thread will set this to cause this thre
auto TestFunc(std::future<bool> promisedExit
, int max
, const char* pszTesting)
{
if (promisedExit.get()) { // The calling thread will set this to cause this thread to exit.
return false;
}
...
...
...
if (max != 10) {
TestFunc(std::move(promisedExit), max++, pszTesting); // Issue is here with std::move(...)
}
...
...
...
}
autotestfunc(std::future promisedExit)
,int max
,const char*pszTesting)
{
如果(promisedExit.get()){//,则调用线程将对此进行设置,以使该线程退出。
返回false;
}
...
...
...
如果(最大!=10){
TestFunc(std::move(promisedExit),max++,pszTesting);//std::move(…)的问题就在这里
}
...
...
...
}
澄清一下,我不确定我是否可以在不改变未来的情况下把未来传下去?i、 是否让未来有效以检查每个递归?使用a,而不是(唯一的)未来
。您可以通过share()
ing您开始使用的future
来获取初始值
auto TestFunc(std::shared_future<bool> promisedExit
, int max
, const char* pszTesting)
{
if (promisedExit.get()) { // The calling thread will set this to cause this thread to exit.
return false;
}
...
...
...
if (max != 10) {
TestFunc(promisedExit, max++, pszTesting);
}
...
...
...
}
autotestfunc(std::shared_future promisedExit)
,int max
,const char*pszTesting)
{
如果(promisedExit.get()){//,则调用线程将对此进行设置,以使该线程退出。
返回false;
}
...
...
...
如果(最大!=10){
TestFunc(promisedExit,max++,pszTesting);
}
...
...
...
}
你说“不行”是什么意思promisedExit
如果你真的离开了它,那么你的未来是空的,所以我要寻找的是一种不移动它而传递未来的方式。谢谢!试试看!:)