草庐IT

conditional-statements

全部标签

c++ - 模板 :Name resolution:Point of instantiation: -->can any one tell some more examples for this statement?

这是来自ISOC++标准14.6.4.1实例化点的声明Forafunctiontemplatespecialization,amemberfunctiontemplatespecialization,oraspecializationforamemberfunctionorstaticdatamemberofaclasstemplate,ifthespecializationisimplicitlyinstantiatedbecauseitisreferencedfromwithinanothertemplatespecializationandthecontextfromwhichi

c++ - std::condition_variable::notify_all() 保证

假设一个条件变量上有N个等待线程(读者),它们被另一个线程(生产者)通知。现在,所有N个读者都将尝试拥有他们引用的unique_lock,一次一个。现在假设生产者出于某些原因想要再次锁定同一个unique_lock,甚至在任何被唤醒的读者开始拥有锁之前。按照标准,只有在所有被通知的读者都开始锁定步骤后,生产者才能成功(尝试)进入其临界区吗? 最佳答案 除了§1.10第2段中给出的相当模糊的调度之外,没有关于调度的保证:Implementationsshouldensurethatallunblockedthreadseventual

c++ - 是否可以定义稍后可以评估的 bool 表达式?

希望实现一种动态表达式,稍后我可以在调用时计算bool值。condition&&=condition2;//notevaluatedjustyetcondition||=condition3;if(condition)//evaluatednowdothis;elsedothis;例如,我在我的代码中使用相同的条件,如果我可以只调整一个语句或添加更多语句,即使在程序运行时也会更容易。conditions=(x>50&&y>200)&&(type==MONKEY);conditions&&=(x稍后在代码中if(conditions)cout编辑:应在if语句中评估条件。

c++ - shared_future<void> 是 condition_variable 的合法替代品吗?

Josuttis指出[“标准库”,第2版,第1003页]:Futuresallowyoutoblockuntildatabyanotherthreadisprovidedoranotherthreadisdone.However,afuturecanpassdatafromonethreadtoanotheronlyonce.Infact,afuture'smajorpurposeistodealwithreturnvaluesorexceptionsofthreads.另一方面,shared_future可以被多个线程使用,以识别另一个线程何时完成了它的工作。另外,一般来说,高级并发

c++ - 为什么condition_variable在producer-consumer中等待锁呢? C++

看下面经典的生产者消费者代码:intmain(){std::queueproduced_nums;std::mutexm;std::condition_variablecond_var;booldone=false;boolnotified=false;std::threadproducer([&](){for(inti=0;ilock(m);std::coutlock(m);while(!done){while(!notified){//looptoavoidspuriouswakeupscond_var.wait(lock);}while(!produced_nums.empty(

c++ - 如何在没有警告的情况下在 gnu++11 标准中写入 "nested if...else statement for constants"?

当我使用嵌套的if....else语句时if(std::is_same::value){//dosomething}elseif(std::is_same::value){//dosomethingelse}...else{//printerror}我收到QACPP静态代码分析器的编译器警告qacpp-4.2.1-4090,其中包含消息“此‘if’语句中的条件是常量。”我该如何修复gnu++11标准中的编译器警告?注意:我不是C++专家,所以如果这个问题听起来很业余,请原谅。 最佳答案 对于T的特定实例,if条件是常量。换句话说st

c++ - condition_variable_any 与 recursive_mutex 一起使用时的行为?

当condition_variable_any与recursive_mutex一起使用时,recursive_mutex是否通常可从其他线程获取,同时condition_variable_any::wait正在等待?我对Boost和C++11实现都很感兴趣。这是我主要关心的用例:voidbar();boost::recursive_mutexmutex;boost::condition_variable_anycondvar;voidfoo(){boost::lock_guardlock(mutex);//Ownershiplevelisnowonebar();}voidbar(){b

c++ - VC++ 和 GCC 下 boost::condition_variable 的不同行为

在我的计算机上,在Windows7上运行,以下代码在带有Boost1.53的VisualC++2010中编译,输出notimeoutelapsedtime(ms):1000使用GCC4.8编译的相同代码(onlinelink)输出timeoutelapsedtime(ms):1000我的意见是VC++输出不正确,应该是timeout。有没有人在VC++中有相同的输出(即notimeout)?如果是,那么它是否是boost::condition_variable的Win32实现中的错误?代码是#include#includeintmain(void){boost::condition_v

C++11 嵌套 std::conditional

这个表达式有什么问题吗?templateusingaddRefU=typenamestd::conditional::type,typenamestd::conditional::type,typenamestd::add_lvalue_reference::type>>::type;intmain(){std::cout>::value>::valuehttp://coliru.stacked-crooked.com/a/21593805f2c6e634因此,它根本没有引用。是否不允许嵌套std::conditional? 最佳答案

c++ - "Why switch statement cannot be applied on strings?"的答案是否仍然正确,即使使用 C++11/14?

我遇到了这个问题:Whyswitchstatementcannotbeappliedonstrings?并想知道答案是否:Thereasonwhyhastodowiththetypesystem.C/C++doesn'treallysupportstringsasatype.Itdoessupporttheideaofaconstantchararraybutitdoesn'treallyfullyunderstandthenotionofastring.仍然适用,即使在C++11/14中使用std:string。是否有多个elseif(...)的替代方案?