草庐IT

-std=gnu99

全部标签

c++ - 是否可以从 std::string 中获取内存(就像 string move ctor 那样)?

如果我的内部类是我自己的vector版本(我控制来源)并且为了举例,我不能将其更改为std::string有没有办法从std::string窃取内存,就像std::string的move构造函数一样做。所以像这样:std::stringstr{"abcdefghijklmnopqrstu"};MyVectorCharClassmvc(std::move(str));//Constructortakesmemoryfromstr我想我听说过一些future的建议,以添加.release()至std::string或std::vector但我说的是现在。 最佳答

c++ - libc++ 中的 std::min 没有悬挂引用

众所周知(或者应该是)绑定(bind)std::min的结果到const引用是一个非常糟糕的主意,每当std::min的参数之一时是右值,因为const引用绑定(bind)不会通过函数返回传播。所以下面的代码#include#includeintmain(){intn=42;constint&r=std::min(n-1,n+1);//risdanglingafterthislinestd::cout应该产生未定义的行为,因为r悬空。事实上,在使用-Wall-O3使用gcc5.2进行编译时编译器吐了warning:isuseduninitializedinthisfunction[-W

opencv - libopencv_calib3d : undefined reference to `std::__throw_out_of_range_fmt(char const*, …)@GLIBCXX_3.4.20'

我提到了this在我的RaspberryPi2上安装OpenCV(它运行在最新的Raspbian上,内核版本为4.1.7-v7)。由于依赖项错误,我无法安装libgtk2.0-dev,但我能够毫无错误地安装OpenCV。我正尝试在Qt中为我的RaspberryPi2交叉编译一些简单的OpenCV代码。但是我在链接器阶段遇到以下错误:/usr/local/lib/libopencv_calib3d.so:undefinedreferencetostd::__throw_out_of_range_fmt(charconst*,...)@GLIBCXX_3.4.20我的代码是:myFunc{

c++ - 为什么 std::stof、std::stod 和 std::stold 处理带有异常的错误?

为什么std::stof的理由是什么?,std::stod,和std::stold抛出异常?http://en.cppreference.com/w/cpp/string/basic_string/stof输入错误是一个常用的例子,说明当通过异常处理错误时不合适(通常用“异常情况”的古怪循环推理来表达,但仍然是一个很好的例子)。C++标准库中并没有以某种方式禁止其他错误处理机制。例如,另一个C++11新人,std::unordered_map::insert系列,表示使用std::pair中的第二个元素失败返回类型。std::unordered_map::insert内的故障功能似乎比

c++ - push_back() "new"一个对象在添加到 c++ 中的 std::list 之前

我是C++标准库的新手。我想使用std::list。我知道如果我自己创建一个列表而不是使用STL,我应该为一个新对象分配内存,然后将它添加到列表中。A类的C风格列表:A*ptrA=newA();ptrA->setElement(value);ptrA->next=null;currentPositionMyCstyleList->next=ptrA;ptrA->prev=currentPositionMyCstyleList;如果我使用STL,是否有必要“新建”一个对象?push_back()在添加到c++中的std::list之前是否“新建”了一个对象?下面的代码是否正确?AaObj

c++ - 打印 std::this_thread::get_id() 给出 "thread::id of a non-executing thread"?

这曾经工作得很好(然后外星人一定黑了我的电脑):#include#includeintmain(){std::cout现在它打印thread::idofanon-executingthread。ideone.com打印了一些ID,但有趣的是是什么导致了我平台上的这种行为。$uname-aLinuxxxx3.13.0-77-generic#121-UbuntuSMPWedJan2010:50:42UTC2016x86_64x86_64x86_64GNU/Linux有什么想法吗?编辑:嗯..当我添加std::cout两行打印相同的ID,但是当我删除它时,结果仍然相同-“非执行线程”。

c++ - 为什么 std::setbase(2) 不切换到二进制输出?

Thecppreferencepageonstd::setbase说:Valuesofbaseotherthan8,10,or16resetbasefieldtozero,whichcorrespondstodecimaloutputandprefix-dependentinput.怎么会?仅支持这些碱基是否有特殊原因?支持至少16个(实际上,最多36个:0-9,然后是a-z)而不必做出任何困难的选择似乎是微不足道的。具体来说,2是一个流行的基础,我认为应该对std::setbase(2)(以及相应的std::binary)感兴趣。我显然可以打印我自己的位,但如果我的ostream能做

c++ - 从 std::true_type 继承 vs static constexpr const bool 成员

我知道这不是一个非常尖锐的问题。使用一个比另一个有优势(编译时间、依赖性、调试符号大小、可用性、可读性等)吗?templatestructIsSharedPtr:std::false_type{};对比templatestructIsSharedPtr{staticconstexprboolvalue=false;};相关问题...templatestructS;templatestructS{};templatestructS{};对比templatestructS;templatestructS{};templatestructS{}; 最佳答案

c++ - 在 std::function 中返回初始值设定项列表而不是 vector

Edit:Itisnotduplicatedofthelinkedquestion(whichisminealso).Hereallthereturntypesarestd::vector.Idonotwanttoreturnaninitializer-list.Iwanttofillthereturnedstd::vectorbyinitializer-listdirectly让我们以这四种情况为例:1)//Acceptablestd::vectorfoo(){returnstd::vector{1};}2)//Acceptablestd::vectorfoo(){return{1}

c++ - 使用模板作为 std::map 中的键

我想知道是否可以使用模板作为map的键。例如:std::map,Node>nodes;本质上,我想要做的是能够拥有一堆包含任意类型数据的节点,并以该数据为键。我想我可以通过将所述数据转换为二进制并以此为键来实现,但这很麻烦,我想避免它。澄清一下,我希望能够使用任何类型的变量作为键。例如,如果我有2个节点,一个包含一个int作为其数据,另一个包含一个Foo作为其数据,我希望能够使用它们的数据作为键将它们放在同一个映射中。也许map不是我想要的,我不确定...想法?谢谢! 最佳答案 如果您没有明确禁用RTTI,请参阅nogard的回答。