草庐IT

optional_argument

全部标签

c++ - 什么是 boost::optional 效率?

我有以下内容:classObj;typedefstd::mapStrMap;std::map>complexMap;问题是,对于complexMap中的某些条目,StrMap将是空的,我根本不会使用它,因此为了提高效率,我正在考虑使用boost::optional。我的问题是boost::optional的效率如何,我担心付出代价最终会一无所获。 最佳答案 将optional视为可以容纳0或1值的容器。您的map已经是一个可以容纳0到N个元素的容器。因此,可选映射是一个容器中的容器,可以容纳0到N个元素。真的,这里没有任何好处。空m

c++ - mutex lock fail with invalid argument 是什么意思?

此代码在我的主进程中调用并编译正常,但在执行时总是抛出以下错误。bounded_bufferbb(200);Producer>producer(&bb);boost::threadproduce(producer);//throwsonthisline这里是执行时总是出现的错误。terminatecalledafterthrowinganinstanceof'boost::exception_detail::clone_impl>'what():boost:mutexlockfailedinpthread_mutex_lock:Invalidargument'classbounded_

c++ - 概念 : checking signatures of methods with arguments

我一直在研究概念。这是一个最小的例子,我试图在其中创建一个基于方法签名的概念:templateconceptboolmyConcept(){returnrequires(Ta,inti){{a.foo()}->int;{a.bar(i)}->int;};}structObject{intfoo(){return0;}intbar(int){return0;}};static_assert(myConcept(),"ObjectdoesnotadheretomyConcept");令我惊讶的是,编写{a.bar(int)}->int不起作用,所以我求助于向requires表达式添加一个额

c++ - reference_wrapper : make_pair VS Class Template Argument Deduction (CTAD)

为什么make_pair和类模板参数推导(CTAD)不同意生成哪种类型?#include#include#include#includeintmain(){intmyInt=5;std::reference_wrappermyIntRef=myInt;automyPair=std::make_pair(myInt,myIntRef);std::pairMy2ndPair(myInt,myIntRef);std::cout输出:St4pairIiRiE//std::pairSt4pairIiSt17reference_wrapperIiEE//std::pair>更新:为什么std::p

c++ - 我的 MFC 套接字代码中的 CAsyncSocket 断言问题和 "improper argument"错误背后的原因是什么?

我被要求为friend查看一些代码。(由于MFC和很多糟糕的代码,我犹豫是对的,但他赢了……)这是一个基于对话框的应用程序,使用了CAsyncSocket。问题表现为一些不间断的调试中断和其他类似的事情——MFCENSURE()宏也有问题——检查套接字是否为空。所有问题都发生在MFC的深处。一些谷歌搜索显示如果在Vista/XP中使用主题可能会发生资源泄漏,但我认为这不是这里的问题。根据我几个小时的调试,代码很差,但基本上它在做以下事情:(建立连接时没有问题-只有没有连接时才会出现这种情况)调用Connect(server,socket)(在派生的CAsyncSocket对象上)在On

c++ - 嵌套模板特化结果为 "Illegal use of explicit template arguments"?

如何专门化嵌套模板?(请参阅下面的错误。)usingstd::reverse_iterator;templatereverse_iteratormake_reverse_iterator(constIt&it){returnreverse_iterator(it);}templateItmake_reverse_iterator>(constreverse_iterator&it){//Above^//errorC2768://'make_reverse_iterator':illegaluseofexplicittemplateargumentsreturnit.base();}

c++ - OpenCV SVM 在火车上抛出异常, "Bad argument (There is only a single class)"

我卡在这个了。我正在尝试通过OpenCV特征2d框架进行一些对象分类,但在训练我的SVM时遇到了麻烦。我能够提取词汇表并使用BowKMeansTrainer对它们进行聚类,但在我从训练数据中提取特征以添加到训练器并运行SVM.train方法后,出现以下异常。OpenCVError:Badargument(Thereisonlyasingleclass)incvPreprocessCategoricalResponses,file/home/tbu/prog/OpenCV-2.4.2/modules/ml/src/inner_functions.cpp,line729terminatec

c++ - 如何包装返回 boost::optional<T> 的 C++ 函数?

我想包装一个返回boost::optional的函数.也就是说,给定:classFoo{boost::optionalfunc();};我想以某种方式包装它,以便Python获得T按值,或None:class_("Foo").def("func",func,return_value_policy);通常如果它只返回一个T,我可以使用:class_("Foo").def("func",func,return_value_policy());但是因为它返回一个boost::optional,它也可以返回boost::none,我希望它最终成为Python的None.有没有办法用现有的转换器

c++ - boost::program_options 如何重新加载一个值

我想从配置文件中重新加载一些值。我知道po::store不会更改存在于variables_map中的值。有没有替代方案可以替换值,即使它们已经存在?我尝试删除即将从variables_map重新加载的值,但是po::store无论如何都不会添加新值(即使旧值不能都可以访问)。 最佳答案 P3trus的解决方案涉及向下转换。这是必要的,因为variables_map重载了std::map::operator[]返回一个constvariable_value&(const防止重新分配)。但是在C++11中我们有std::map::at(

c++ - std::map.insert "could not deduce template argument for..."

我正在尝试熟悉STL库,但我无法理解我的编译错误。我使用编译器错误字符串“无法推断...的模板参数”搜索了其他问题,但没有一个答案似乎适用或相关。Error4errorC2784:'boolstd::operator&,conststd::unique_ptr&)':couldnotdeducetemplateargumentfor'conststd::unique_ptr&'from'conststd::string'c:\programfiles(x86)\microsoftvisualstudio10.0\vc\include\xfunctional125我正在编写一个简单的解释