Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++11 C++;标准:未来<;布尔>;在递归函数中_C++11_Promise_Std - Fatal编程技术网

C++11 C++;标准:未来<;布尔>;在递归函数中

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

考虑到以下情况,是否可以递归到函数中?我认为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 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
如果你真的离开了它,那么你的未来是空的,所以我要寻找的是一种不移动它而传递未来的方式。谢谢!试试看!:)