草庐IT

null-propagation-operator

全部标签

c++ - 绑定(bind) lambda 的速度(通过 std::function)与仿函数结构的 operator()

autolam=[](inta,intb,intc){returna在版本一中,我们std::vector>lamvals;//getparametersandforeachlamvals.emplace_back(std::bind(lam,a,std::placeholders::_1,b));替代方案是std::vectorlamvals;//getparametersandforeachlamvals.emplace_back(functor{a,b});在这两种情况下我们都有一个简单的迭代returnstd::any_of(lamvals.cbegin(),lamvals.c

c++ - boost shared_ptr : difference between operator= and reset?

下面两段代码有区别吗?它们中的任何一个比另一个更可取吗?运算符=boost::shared_ptrfoo;//foo.ptrshouldbeNULLfoo=boost::shared_ptr(newBlah());//Involvescreationandcopyofashared_ptr?重置boost::shared_ptrfoo;//foo.ptrshouldbeNULLfoo.reset(newBlah());//foo.ptrshouldpointnowtoanewBlahobject注意:我需要定义shared_ptr然后将其设置在不同的行中,因为我在一段代码中使用它,例如

c++ - 我可以检查 C++ 迭代器是否为 null 吗?

我在使用vector迭代器时遇到了问题。我在一些地方读到过,检查空迭代器是不可能的,检查迭代器的常用方法是在搜索后根据vector.end()检查它。例如:vectoranimalList;vector::iteratorfindInList(consttype_info&type){//LoopthroughlistofAnimals,ifDogfound,returniteratortoit}autoit=findInList(typeid(Dog));//WithapointerIcancheckifit'snull,butwithaniteratorIhavetocheckag

c++ - 这是实现通用 operator== 和 operator< 的安全方法吗?

看到thisquestion之后,我的第一个想法是定义通用等价和关系运算符是微不足道的:#includetemplatebooloperator==(constT&a,constT&b){returnstd::memcmp(&a,&b,sizeof(T))==0;}templatebooloperatorusingnamespacestd::rel_ops然后会变得更有用,因为它会被运算符的默认实现完全通用==和.显然,这不会执行成员比较,而是按位比较,就好像该类型只包含POD成员一样。这与C++生成复制构造函数的方式并不完全一致,例如,确实执行成员复制。但是我想知道上面的实现是否真的

c++ - 使用 bool operator== 比较对象

所以,看了一些SO问答,还是不明白为什么要用friendbooloperator==(BaseClassconst&left,BaseClassconst&right)代替booloperator==(BaseClassconst&right)现在我有这样的东西http://pastebin.com/pKsTabC0(已修复)-它似乎工作正常。但也许我错过了什么?有什么建议吗?更新1好的,我更改了源以使其正常工作http://ideone.com/fIAmB.删除了不必要的virtual并添加了const。我仍然不明白为什么要使用friend... 最佳答案

c++ - 将默认构造的迭代器与 operator== 进行比较

C++标准是否说我应该能够比较两个默认构造的STL迭代器是否相等?默认构造的迭代器是否具有相等可比性?我想要以下内容,例如使用std::list:voidfoo(conststd::list::iteratoriter){if(iter==std::list::iterator()){//Something}}std::list::iteratori;foo(i);我在这里想要的是类似于迭代器的NULL值,但我不确定它是否合法。在VisualStudio2008附带的STL实现中,它们在std::list的operator==()中包含断言以排除这种用法。(他们检查每个迭代器是否由同一

c++ - 当我只想禁用它时,自定义赋值 operator=() 的签名是否重要?

我需要禁用复制赋值运算符。这将起作用:A&operator=(constA&);如果我不为operator=指定确切的参数,它会工作吗?我的意思是这样的:voidoperator=(void);返回值是对的,我可以随便写,但是参数类型呢?这会覆盖类的默认operator=吗? 最佳答案 来自12.8p17C++标准草案:Auser-declared copy assignmentoperatorX::operator= isanon-staticnon-templatememberfunctionofclass X withexac

c++ - 为什么要检查 if (*argv == NULL)?

这个问题在这里已经有了答案:Whencanargv[0]havenull?(4个答案)关闭5年前。在我目前正在学习的数据结构类(class)中,我们的任务是用C++编写网络爬虫。为了让我们抢先一步,教授为我们提供了一个从给定URL获取源代码的程序和一个简单的HTML解析器来去除标签。该程序的主函数接受参数,因此使用argc/argv。用于检查参数的代码如下://Processtheargumentsif(!strcmp(option,"-h")){//dostuff...}elseif(!strcmp(option,"")){//dostuff...}elseif(!strcmp(op

c++ - Operator= 在 C++ 中重载

在C++Primer一书中,它有一个C风格字符数组的代码,并在文章15.3Operator=中展示了如何重载=运算符。String&String::operator=(constchar*sobj){//sobjisthenullpointer,if(!sobj){_size=0;delete[]_string;_string=0;}else{_size=strlen(sobj);delete[]_string;_string=newchar[_size+1];strcpy(_string,sobj);}return*this;}现在我想知道为什么下面这段代码做同样的工作时需要返回一个

android - ndk-build 失败,process_begin : CreateProcess(NULL, uname -a, ...) 失败

我正在Windows8上使用AndroidStudio开发一个android应用程序,我正在使用一些native代码。突然间我无法编译我的C文件。当我运行ndk-build时,出现以下错误:process_begin:CreateProcess(NULL,uname-a,...)failed.process_begin:CreateProcess(NULL,uname-r,...)failed.Thesystemcannotfindthepathspecified.'mount'isnotrecognizedasaninternalorexternalcommand,operablep