草庐IT

block_test

全部标签

c++ - 在现代 C++ 中使用 try..catch block 通过模板元编程包装任意函数调用

我想创建一些模板,基本上应该包装它的参数。参数应该是一个任意的函数调用,它通过一些带有前缀和后缀代码的模板元编程魔法被包装。我想像下面这样使用它:autoresult=try_call(some_vector.at(13));和try_call将以某种方式定义,它将try..catchblock包装在some_vector.at(13)周围。像这样:template//sometemplatemetaprogrammingmagicheretry{autovalue=//executetheparameterhere,i.e.some_vector.at(13);returnstd::

c++ - 为什么成员函数尝试 block 处理程序中的 lambda(捕获 'this')不能访问 VC++ 2013 中的私有(private)数据成员?

与thisquestionaboutstaticinitializers不同但可能相关.前两个函数编译良好,最后一个函数在vc++中不编译,但在clang和gcc中编译:classA{protected:std::stringprotected_member="yay";public:voidwithNormalBlock();voidwithFunctionBlock();voidnoLambda();};voidA::withNormalBlock(){try{throwstd::exception();}catch(...){[this](){std::coutinclang(好

C++ 重构 : conditional expansion and block elimination

我正在重构大量代码(主要是C++),以删除一些已永久设置为给定值的临时配置检查。因此,例如,我将有以下代码:#include#include#include...if(value1()){//dosomething}boolb=value2();if(b&&anotherCondition){//domorestuff}if(value3()对value的调用返回bool或int。因为我知道这些调用总是返回的值,所以我做了一些正则表达式替换以将调用扩展到它们的正常值://where://value1()==true//value2()==false//value3()==4//TODO

c++ - 外部链接和 »extern "C"« block

我有一个intID,我想在C++中定义它并使其可用于C链接(为简单起见设计的案例):/*i.h*/#ifdef__cplusplusextern"C"{#endifexternintID;#ifdef__cplusplus}#endif这是一个使用int的C和C++程序:/*m.cpp*/#include"i.h"#includeintmain(){std::coutintmain(){printf("%d\n",ID);}现在我想知道的是extern"C"和/或extern的语法。以下是可以和不能定义intID的方式:/*i.cpp*///constintID=88;//noClin

c++ - 定义 BOOST_TEST_DYN_LINK 会导致应用程序在 Visual Studio 中崩溃

在boost单元测试文档中,它明确指出您需要定义BOOST_TEST_DYN_LINK为了与boost单元测试库链接。我正在使用这个基本示例:#defineBOOST_TEST_DYN_LINK#defineBOOST_TEST_MODULEtest_module1//Thisheaderisforthedynamiclibrary,nottheheaderonlyone#includeBOOST_AUTO_TEST_CASE(test1){BOOST_CHECK(true);}我已将boost添加到我的包含/库路径并且代码编译正常,但是当我使用VisualStudio编译boost单

c++ - 使用函数尝试 block 从构造函数中抛出两次异常

为什么类A的构造函数抛出的以下异常会被捕获两次,第一次被构造函数本身的catch捕获,第二次被main函数中的catch捕获?为什么它不被构造函数中的catch捕获一次?#includeusingnamespacestd;classE{public:constchar*error;E(constchar*arg):error(arg){}};classA{public:inti;A()try:i(0){throwE("ExceptionthrowninA()");}catch(E&e){cout如果我删除主函数中的try-catchblock,程序就会崩溃。这是输出:Exception

c++ - Gtest : test compiling error

我正在尝试测试我用googletest编写的电机控制库,但我没有编译测试代码。测试位于名为test.cpp的文件中,如下所示:#include#include"../motor.hpp"TEST(constructorTest,contructorDefault){}我将测试主函数放在另一个名为main.cpp的文件中。#include#include"../motor.hpp"intmain(intargc,char*argv[]){::testing::InitGoogleTest(&argc,argv);RUN_ALL_TESTS();}为了编译,我执行了以下行:g++main.

c++ - 从一个稀疏矩阵中提取一个 block 作为另一个稀疏矩阵

如何从Eigen::SparseMatrix中提取一个block.似乎没有我用于密集的方法。‘classEigen::SparseMatrix’hasnomembernamed‘topLeftCorner’‘classEigen::SparseMatrix’hasnomembernamed‘block’有一种方法可以将block提取为Eigen::SparseMatrix? 最佳答案 我创建了这个函数来从Eigen::SparseMatrix中提取blocktypedefTripletTri;SparseMatrixsparseBl

c++ - block 矩阵乘法

关闭。这个问题需要debuggingdetails.它目前不接受答案。编辑问题以包含desiredbehavior,aspecificproblemorerror,andtheshortestcodenecessarytoreproducetheproblem.这将有助于其他人回答问题。关闭6年前。Improvethisquestion我想进行分块矩阵乘法(将一个矩阵分成多个sxs矩阵,再将相应的分块相乘)。我写的代码如下Hennesy的架构书示例代码:for(intjj=0;jj(n/s)?(n/s):(jj+s-1));j++){temp=0;for(intk=kk;k(n/s)?

c++ - 正常 block 后检测到堆损坏

我有以下代码,我不确定为什么当它命中Myclass的析构函数时我会收到堆损坏检测错误。我相信我正在正确地释放内存??#include#includeusingnamespacestd;classMyClass{private:char*mp_str;public:MyClass():mp_str(NULL){}~MyClass(){delete[]mp_str;}voidsetString(constchar*str);voidprintString();};intmain(){MyClass*a=newMyClass();std::vectormyVector;myVector.pu