草庐IT

container_storage_type

全部标签

C++/LLVM : Runtime code generation and STL container

假设一个简单的部分评估场景:#include/*maybeknownatruntime*/intsomeConstant();/*canbepartiallyevaluated*/doublefoo(std::vectorargs){returnargs[someConstant()]*someConstant();}假设someConstant()是已知的并且在运行时不会改变(例如,由用户提供一次)并且可以被相应的int文字替换。如果foo是热路径的一部分,我预计会有显着的性能改进:/*partiallyevaluated,someConstant()==2*/doublefoo(s

c++ - C++ 中的 `container_of` 宏,具有与 C 相同的签名

我的代码使用著名的container_of宏来实现仅包含宏的链表库。它在C中完美运行。现在我想在它上面支持C++,所以我需要一个container_of替换C++,它匹配以下签名:container_of(ptr,type,member)C实现是这样的:#definecontainer_of(ptr,type,member)({\consttypeof(((type*)0)->member)*__mptr=(ptr);(type*)((char*)__mptr-offsetof(type,member));}) 最佳答案 为自己量身

C++初阶:容器(Containers)vector常用接口详解

介绍完了string类的相关内容后:C++初阶:适合新手的手撕string类(模拟实现string类)接下来进入新的篇章,容器vector介绍:文章目录1.vector的初步介绍2.vector的定义(constructor)3.vector迭代器(iterator)4.vector的三种遍历4.1正常for循环4.2范围for循环4.3两种迭代器(正向和反向)5.vector扩容相关(resize和reserve)5.2reserve()5.2resize()6.vector增删查改6.1push_back和pop_back6.2find、Insert、erase6.3swap1.vecto

c++ - GCC 7,aligned_storage 和 "dereferencing type-punned pointer will break strict-aliasing rules"

我编写的代码在GCC4.9、GCC5和GCC6中没有警告。它在一些较旧的GCC7实验快照(例如7-20170409)中也没有警告。但在最近的快照(包括第一个RC)中,它开始产生关于别名的警告。代码基本上可以归结为:#includestd::aligned_storage::typestorage;intmain(){*reinterpret_cast(&storage)=42;}使用最新的GCC7RC编译:$g++-Wall-O2-cmain.cppmain.cpp:Infunction'intmain()':main.cpp:7:34:warning:dereferencingtyp

c++ - 从模板化模板类和可变模板中声明 "container"对象

我需要声明一个可以存储不同类型容器的类。即,如果它可以处理std::bitset和std::array就好了。但是,这两个类需要不同的模板参数......是否可以(以及可能如何)使用模板化模板类和可变参数模板来声明此类类?示例(但错误):templateclassContainer,std::size_tN,typename...Args>classBase_Class{...Containercontainer;};编译器提示N/2不是类型。显然,对于std::array和std::bitset,我需要将大小作为最后一个模板参数……是否可以编写这种疯狂的代码?谢谢!编辑:就我而言,主

c++ - 设计建议——返回子类时避免 "invalid covariant return type"

我有以下情况:我指定一个纯虚函数:虚拟PredictedMatchPredictMatch(constMatch&match)const=0;我还有:类ImpactPredictedMatch:publicPredictedMatch现在,我想做的是:ImpactPredictedMatchPredictMatch(constMatch&match)const;在一个实现了之前的纯虚函数的类中。我原以为编译器会根据需要简单地转换返回的类型,但我得到:impact_predictor.h:18:24:错误:“虚拟ImpactPredictedMatchImpactPredictor::P

c++ - 错误 : argument of type char* is incompatible with parameter of type LPCWSTR

#include#includeusingnamespacestd;intmain(){char*file="d:/tester";WIN32_FIND_DATAFindFileData;HANDLEhFind;hFind=FindFirstFile(file,&FindFileData);//lineoferrorsaysargumentoftypechar*isincompatiblewithparameteroftypeLPCWSTR}我无法理解错误。错误是什么以及如何解决错误?我正在制作一个控制台应用程序,需要检查目录中是否有文件。 最佳答案

c++ - boost .python : Argument types did not match C++ signature

我在python中调用C++函数时遇到一个奇怪的问题。我公开了一个我想从中调用函数的类:class_>("MyClass",init())//....def("someFunc",&MyClass::someFunc);我得到一个std::shared_ptr来自另一个类的成员变量,该类通过.def_readonly(...)公开当我尝试调用该函数时,出现以下错误:File"pytest.py",line27,intest_funccu.someFunc("string")Boost.Python.ArgumentError:PythonargumenttypesinMyClass.s

C++ 从 ‘const type* const’ 到 ‘type*’ 的无效转换

我有一个非常愚蠢的问题(我认为)。很长时间没有用C++编码,但我无法弄清楚这个问题。我有这个类:#includeclassNode{private:QList_adjacent;public:Node();boolisConnectedTo(Node*n)const;};isConnectedTo()的实现:boolNode::isConnectedTo(Node*n)const{return_adjacent.contains(n)&&n->_adjacent.contains(this);}我在return行中收到以下错误:Node.cpp:Inmemberfunction‘con

c++ - typedef type * type::* ,它是什么?

我有以下代码:structmyType{myType*ptr;};typedefmyType*myType::*other_type;第二行typedef'ining是什么?这是一个返回myType指针或其他东西的成员函数吗? 最佳答案 将other_type定义为指向myType成员的指针,其中所述成员本身是指向myType的指针。例如,您可以这样使用它:other_typex=&myType::ptr;myTypemine;mine.*x=&mine;为什么你会这样做,我不能说。 关