草庐IT

is_unique

全部标签

c++ - boost static_vector 而不是 std::is_trivially_destructible

根据thisexample(左例)#include#includestructX{intk;std::arraya;boost::container::static_vectorb;~X()=default;};inthuh(){std::arrayx;return0;}看起来像boost::container::static_vector当T时可以轻易破坏是(当b被销毁时,不会在X上循环)。huh优化为xoreax,eax;ret(即return0不遍历数组。当我改用具有非平凡析构函数的包含类型时(右例)#include#includestructY{~Y();};structX{i

c++ - 编译器错误 : ‘std::array<...>::~array()’ is implicitly deleted

我有以下.hpp文件:#ifndefCODE_HPP#defineCODE_HPP#include#includeusingstd::vector;usingstd::array;template>classstack;template,typenameK=stack>classstack_array;templateclassstack{Cpile;stack();~stack();voidpush(T&);friendclassstack_array>;};templateclassstack_array{private:staticconstsize_tmax_elem=10;a

c++ - 警告: "when type is in parentheses, array cannot have dynamic size"?的原因是什么

我已经发布了一个关于与数组的动态内存分配相关的GCC错误的问题:Anerrorisissuedbygccrelativetoparsingtype-idinanewexpression现在使用ClangHEAD10.0.0我收到以下警告:rog.cc:9:37:warning:whentypeisinparentheses,arraycannothavedynamicsizeint(**a)[N3]=new(int(*[n1])[N3]);~~^~~当我运行这个演示程序时:#includeintmain(){constsize_tN3=4;size_tn1=2;int(**a)[N3]

c++ - BOOST_FOREACH : What is the error on using this of a STL container?

有谁知道为什么以下会在VC9上产生错误?classElem;classElemVec:publicvector{public:voidfoo();};voidElemVec::foo(){BOOST_FOREACH(Elem&elem,*this){//Dosomethingwithelem}return;}我得到的错误是:errorC2355:'this':canonlybereferencedinsidenon-staticmemberfunctions我现在拥有的唯一(hack)解决方案是:voidElemVec::foo(){ElemVec*This=this;BOOST_FO

1071 - Specified key was too long; max key length is 3072 bytes Mysql报错解决方法

错误信息“Specifiedkeywastoolong;maxkeylengthis3072bytes”是在MySQL数据库中创建索引时可能出现的问题,通常出现在尝试创建一个过长的唯一键(UNIQUEKEY)或主键(PRIMARYKEY)时。MySQL对于InnoDB存储引擎有一个索引键长度的限制,这个限制基于字符集的不同而不同。例如,在使用utf8字符集时,每个字符可能占用3个字节,那么对于innodb表,索引键的最大长度大约为1000个字符左右(因为3072/3≈1024)。若字符集是utf8mb4,每个字符可能占用4个字节,所以最大长度会进一步减少到768个字符左右(3072/4=768

c++ - 使用带有自定义释放器的 std::unique_ptr 来包装原始指针

我正在尝试使用libsvm对于某个复杂的应用程序,并且由于libsvm主要是一个C库,因此在加载某些数据后,必须使用自定义API函数来释放内存。这就是我的意思:structsvm_model*model;model=svm_load_model("pathtomodelfile");//dosomeprocessingsvm_free_and_destroy_model(&this->model);这些是我使用的libsvmAPI函数的定义:structsvm_model*svm_load_model(constchar*model_file_name);voidsvm_free_an

c++ - 动态分配数组的 unique_ptr 替代方案

我写了一个类,它必须与一些需要一些C风格数组(或至少指向第一个元素的指针)作为参数的旧代码接口(interface)。这些数组是我类的成员,它们特别大(50kb)所以我想把它们放在堆上,这样我类的对象在堆栈上就不会很大。我非常相信使用资源管理对象,所以我宁愿自己不在堆上管理这些数组。我发现使用unique_ptr的效果特别好。例如:std::unique_ptrsomeArrayName并使用:someArrayName(newSOMETYPE[someLargeSize])在我的构造函数的初始化列表中。这允许我使用.get()将它们用作常规C数组需要它作为参数的函数的方法,我不必自己

c++ - 为什么 GCC 给我一个错误 : no unique final overrider?

在下面的代码中,我收到以下警告和错误:test.cpp:15:warning:directbase'B'inaccessiblein'D'duetoambiguitytest.cpp:15:error:nouniquefinaloverriderfor'virtualvoidA::f()'in'D'但是如果我从A中移除B的虚拟继承(即structB:publicA),我只会得到警告,没有错误。structA{virtualvoidf()=0;};structB:publicvirtualA{voidf(){}};classC:publicB{};structD:publicC,virt

c++ - 为什么 list<unique_ptr> 中的 unique_ptr 的 std::move() 没有真正 move 它?

usingPtr=std::unique_ptr;Ptrf(boolarg){std::listlist;Ptrptr(newint(1));list.push_back(std::move(ptr));if(arg){Ptr&&obj1=std::move(list.front());//Here|obj1|and|list.front()|stillpointtothesamelocation!list.pop_front();returnstd::move(obj1);}else{Ptrobj2=std::move(list.front());list.pop_front();r

c++ - 构造函数中抛出的异常 : is the destructor called?

这个问题在这里已经有了答案:Whatdestructorsarerunwhentheconstructorthrowsanexception?(3个答案)关闭8年前。如果在对象的构造函数中抛出异常,那么是否会调用析构函数?还是未定义的行为?(这就是为什么我不愿意说出我的编译器做了什么。)structfoo(){foo(){throw"bar";}~foo(){/*amIcalled*/}};foof;