草庐IT

try_integer

全部标签

c++ - C++中的try catch在未命中时会影响性能吗

我有一段代码,其中函数中有一个trycatch并且函数被命中。100+次。代码每次都提早返回,而没有实际命中trycatch。这会影响VisualStudio中的性能吗?我看到了性能影响。我的代码是:voidfoo(inta){if(a>value){return;}try{possibleErrorFunction();}catch{}}我把它改成:voidfoo(inta){if(a>value){return;}bar();}voidbar(){try{possibleErrorFunction();}catch{}}第二个代码似乎快了大约10秒。对此有什么合理的解释吗?

c++ - 如何使 rValue 引用在 RR 获取其值的 try block 之外可用?

假设我们不想重新设计函数a_func_that_may_throw。try{T&&rr=a_func_that_may_throw();}catch(conststd::exception&e){/*Dealwiththeexceptionhere.*/}//Question:Howtoadaptthecodeabovesoastohave`rr`availablehere?抱歉没有问清楚我的问题。添加以下内容(希望)使问题更清楚。我们可以对指针这样做:T*ptr=nullptr;try{ptr=a_source_that_may_throw();}catch(conststd::ex

c++ - gcc 和 g++ 错误 : error trying to exec 'cc1plus' : execvp: No such file or directory

我在编译时遇到问题.c和.cpp使用gcc的文件和g++,对于这两种情况,我都收到了消息:g++(orgcc):errortryingtoexec'cc1plus':execvp:Nosuchfileordirectory`我已经尝试重新安装gcc和g++并确保它们的版本相同。编辑:我使用的是ubuntu16.04.1LTS,g++和gcc的版本都是5.4.020160609。以下是echo|g++-v-xc++-fsyntax-only-的输出:Usingbuilt-inspecs.COLLECT_GCC=g++Target:x86_64-linux-gnuConfiguredwit

c++ - 为什么我收到错误 : initializing argument 1 of 'Item::Item(int)' [-fpermissive] in Eclipse when I try to compile my C++ code?

我是C++的新手,在盯着它看了太久之后终于放弃了尝试编译它。编译器似乎出于某种原因拒绝了头文件中的构造函数原型(prototype)......我无法弄清楚它有什么问题。项目.h:#ifndefITEM_H_#defineITEM_H_classItem{public:Item(int);//ThislineiswhatEclipsekeepsflaggingupwiththeerrorinthetitlevirtual~Item();Item*getNextPtr();intgetValue();voidsetNextPtr(Item*);};#endif/*ITEM_H_*/在我的

c++ - 在构造函数 C++ 中处理 Try-catch block

我面临这样一种情况,我需要在构造函数中使用try-catchblock。特别是,构造函数尝试调用tryblock中的函数,如果失败,它将调用另一个函数来设置一些值。在这两种情况下,构造函数都应该正确地创建对象,并且在这两种情况下它都必须在结束之前调用一些其他方法。情况如下:classA{A(inti){try{setDevice(i);}catch(DeviceException&ex){setDevice(0);throwex;}otherMethod();}}但是,如果在tryblock中发生错误,则不会调用otherMethod(),因为执行在catchblock内结束,我不能像

c++ - C++ 如何处理 try catch block 中的赋值?

我使用clang分析器检查我的C++代码是否存在缺陷和错误。我有以下构造:#include#includedoublesomethingThatMayThrow()throw(std::exception){if(rand()%2){throwstd::exception();}return5.0;}intmain(){doublevalue=2.0;try{value=somethingThatMayThrow();}catch(conststd::exception&){std::cout分析器现在提示变量value的初始值从未被读取。但是,很明显,当且仅当tryblock中出现异

c++ - boost::phoenix try_catch_all 构造编译失败

我正在编写用于日期解析的boost::spirit::qi语法。#include#include#includetemplatestructdate_rfc1123_grammar:boost::spirit::qi::grammar{typedefboost::gregorian::datevalue_type;date_rfc1123_grammar():date_rfc1123_grammar::base_type(date){namespaceqi=boost::spirit::qi;namespacephx=boost::phoenix;usingqi::_pass;usin

c++ - 查找值在 std::integer_sequence 中第一次出现的位置

我想找到一个值在std::integer_sequence中第一次出现的位置。标准库中是否有用于此任务的算法?如果没有,什么是做这件事的好方法?--下面是我的尝试。它有效,但我觉得它不是很优雅;当值不存在时(代码因编译而被注释掉),它也无法产生干净的错误(“未找到值”)。(此外,必须在Find_in_integer_sequence中指定整数类型感觉有些多余,但我认为没有办法解决它。)代码仅供您娱乐,不应作为建议解决方案的起点。#include#include#includenamespacedetail{templatestructFind;templatestructFind_im

c++ - VS2013 错误 : LNK2019 When trying to build ZeroMQ server

我正在尝试在VisualStudio2013上用C++构建这个简单的ZeroMQ服务器。#include"stdafx.h"#include"zmq.hpp"#include#include#includeusingnamespacestd;int_tmain(intargc,_TCHAR*argv[]){//Preparecontextandsocketzmq::context_tctx(1);zmq::socket_tsckt(ctx,ZMQ_REP);sckt.bind("tcp://*:5555");while(true){zmq::message_trequest;//Wai

c++ - 使用 try_lock boost 锁定

我正在尝试解决Boost1.46.1的锁定问题-我尝试了一些方法但我不满意-因此很想听听干净的意见。线程A:必须始终等待并获取关键数据部分的锁更新一些关键数据手动解锁(或范围)线程B-绝不能阻塞(try_lock?)-如果获得锁,从提到的关键部分读取数据我不确定我是否需要shared_lock或者我是否可以用其他方式解决这个问题。编辑,我的代码如下:线程A:{//Criticalsectionboost::mutex::scoped_locklock(_mutex);}线程B:boost::mutex::scoped_locklock(_mutex,boost::try_to_lock