草庐IT

SEARCH_TYPE_DISPATCH

全部标签

c++ - 检测某些非数字类型 T 的 std::numeric::type<T> 的特化

我想检查一个类型是否在std::numeric_limits中有一个条目。当类型是一个数组时——(或者可能不是一个数字?)我得到一个编译器错误。这使我无法根据std::numeric_limits是否支持该类型来检测和分支。如果有人愿意分享任何见解,我将不胜感激。//thefollowingprovokescompilererroronClang//Functioncannotreturnarraytype'type'(aka'char[20]')static_assert(!std::numeric_limits::is_specialized,"!std::numeric_limi

c++ - 无法使用自动参数化 true_type 检测 T::value()

使用SFINAE,has_value_int和has_value_auto两者都尝试检测类T是否有一个staticconstexpr名为value的函数.使用int参数化true_type,has_value_int效劳于演示类(class)pass和fail.使用auto参数化true_type,has_value_auto总是返回false。使用int有什么区别?并使用auto,为什么auto不工作?具体来说,为什么重载决策更喜欢match_auto(...)至match_auto(int)?#includeusingnamespacestd;//parametrizetrue_t

c++ - 可以用 0 计数调用 std::search_n 吗?

std::search_n可以被“安全地”调用且count为0吗?具体来说,像下面这样的代码是否有效?#include#includeintmain(intargc,char*argv[]){constinttest[7]={1,2,3,4,5,6,7};constint*constlocation=std::search_n(test,test+7,0,8);if(location==test){std::puts("Founditatthebeginning!");}}我希望此代码到达std::puts语句,并且大多数std::search_n的描述似乎暗示它会。但是,我发现的大多

c++ - 是否可以根据type_info创建对象?

差不多就是标题:可以根据type_info创建对象吗?这样做的目的是推迟对象的创建。例如,这是原始的“未延迟”代码:Foo*a=newFoo();Bar*b=newBar();这是延迟的://Storetypeindicesintoavectorstd::vectortypes;types.push_back(std::type_index(typeid(Foo)));types.push_back(std::type_index(typeid(Bar)));//Iteratethroughvector,createobjects?Isitpossible?如果这不可能,是否有任何其他

c++ - 在模板参数中使用时,type_trait<T>{} 中的 {} 的作用是什么?

我经常在模板代码中看到此{}的出现。我不确定我明白它在做什么。例如:std::enable_if_t{}&&!std::is_same{}>>这里的{}是什么?它是在实例化类型吗?模板参数是什么意思?据我所知,实例化一个类型意味着创建一个对象。您如何在这种情况下创建对象?它只是创建一个虚拟对象吗?为什么要这样做?这样做的意义和目的是什么? 最佳答案 在这种情况下,type_trait{}相当于type_trait::value.您的示例等效于以下内容:std::enable_if_t::value&&!std::is_same::v

使用 -O1 编译时 C++ regex_search 中断

这个问题在这里已经有了答案:Inconsistentbehaviorofstd::regex(1个回答)关闭3年前。示例代码:#include#include#includeintmain(){std::regexnpat(R"(^(\d+))");std::smatchm;std::regex_search(std::string("10"),m,npat);std::cout编译时g++-std=c++11main.cpp输出是2m.str(1):|10|10这是预期的。但是,当用编译时g++-std=c++11-O1main.cpp输出变成libc++abi.dylib:term

c++ - "Class type redefinition"头文件和源文件之间的错误

所以我遇到了一个问题,我确信有一个非常明显的解决方案,但我似乎无法弄清楚。基本上,当我尝试在我的头文件中进行类定义并在我的源文件中进行实现时,我收到一条错误消息,提示我正在重新定义我的类。使用VisualC++2010Express。确切错误:“错误C2011:‘节点’:‘类’类型重新定义”示例代码如下:节点.h:#ifndefNODE_H#defineNODE_H#includeclassNode{public:Node();Node*getLC();Node*getRC();private:Node*leftChild;Node*rightChild;};#endif节点.cpp:

c++ - 没有匹配函数调用 ‘regex_search(...)'

给定一个旧式constchar*指针和一个长度,有没有一种方法可以调用std::regex_search()而无需先复制其内容缓冲区到std::string?这是我遇到的问题的一个简单示例:#includeintmain(){constchar*text="123foobar456";constsize_tlen=strlen(text);conststd::regexrx("(.+)bar");std::smatchwhat;std::regex_search(text,text+len,what,rx);//我认为需要两个迭代器的第5个std::regex_search()是我需要

Content-Type:application/x-msexecl;是干什么的?底层原理是什么?

Content-Type:application/vnd.ms-excel是用于设置HTTP响应头中的Content-Type字段,指定返回的内容类型为MicrosoftExcel文件(.xls)。Content-Type是HTTP协议中的一个字段,用于指定传输的数据的类型和格式。通过设置Content-Type头部字段,服务器可以告知客户端接收到的数据的类型,以便客户端正确处理和解析数据。application/vnd.ms-excel是指定MicrosoftExcel文件类型的MIME类型。MIME(MultipurposeInternetMailExtensions)是一种标准化的数据格

c++ - 什么是单次 dispatch 和双重 dispatch ?

我已经写了访问者模式如下,但我不明白什么是单次和双次分派(dispatch)。AFAIK,单分派(dispatch)是根据调用者类型调用方法,而双分派(dispatch)是根据调用者类型和参数类型调用方法。我猜双重调度发生在单个类层次结构中,但为什么访问者类具有两个类层次结构但它仍然被视为双重调度。voidfloppyDisk::accept(equipmentVisitor*visitor){visitor->visitFloppyDisk(this);}voidprocessor::accept(equipmentVisitor*visitor){visitor->visitPro