草庐IT

template-matching

全部标签

C++ regex_match 不工作

这是我的部分代码boolCSettings::bParseLine(constchar*input){//_asmINT3std::stringline(input);std::size_tposition=std::string::npos,comment;regexcvarPattern("\\.([a-zA-Z_]+)");regexparentPattern("^([a-zA-Z0-9_]+)\\.");regexcvarValue("\\.[a-zA-Z0-9_]+[]*=[]*(\\d+\\.*\\d*)");std::cmatchmatchedParent,matched

c++ - C++ 代码错误 "expected constructor, destructor, or type conversion before ‘(’ token ”和 "no matching function for call to ..."

真正尝试解决错误,仔细检查所有内容。请帮忙。c++新手,请多关照。头文件(.h)#ifndefGUARD_Optimized_quick_sort_h#defineGUARD_Optimized_quick_sort_h#include#include#includeusingnamespacestd;templateclassoptimized_quick_sort{public:optimized_quick_sort(vectorarray){this->array=array;}optimized_quick_sort(listarray){vectortemp(array.b

c++ - "No match for operator="试图在 C++ 中遍历映射

我正在尝试遍历定义如下的map:std::map>ridx_;现在我尝试在以下重载运算符的友元函数中遍历ridx_(它是一个类的私有(private)成员)std::ostream&operator>::iteratorit;//Thefollowingisline34for(it=m.ridx_.begin();it!=m.ridx_.end();it++)osfirst但是g++错误输出:SMatrix.cpp:34:error:nomatchfor'operator='in'it=m->SMatrix::ridx_.std::map::beginwith_Key=unsigned

C++ : friend declaration ‘declares a non-template function

我在重载时遇到问题流运算符(operator),我找不到解决方案:templateclassNVector{inlinefriendstd::ostream&operator&rhs);};templateinlinestd::ostream&NVector::operator&rhs){/*SOMETHING*/returnlhs;};它产生以下错误信息:warning:frienddeclaration‘std::ostream&operatorerror:‘std::ostream&NVector::operator如何解决这个问题?非常感谢。 最佳答

c++ - 错误 : expected primary-expression before ‘>’ : templated function that try to uses a template method of the class for which is templated

这个问题在这里已经有了答案:WhereandwhydoIhavetoputthe"template"and"typename"keywords?(8个答案)关闭8年前。在使用模板和仿函数(未出现在这个问题中)时,我最终遇到了以下简化的问题。以下代码(也可用here)classA{public:templateboolisGood(intin)const{constTf;returninbooltryEvaluator(T&evaluator,intvalue){returnevaluator.isGood(value);}intmain(intargc,constchar*argv[]

C++ 如何使 template<T>f() 为整数 T 返回 -1,为指针类型返回 nullptr

我需要完成以下任务:templatef(){:return{-1ifTisofintegraltype,elsenullptr}}在我的特定用例中,T可以是四种类型之一:intPy_ssize_t//ssize_tPy_hash_t//ssize_tPyObject*//PyObjectissomeCstruct这是我迄今为止最好的解决方案:templateTtest(typenameenable_if::value,void*>::type=nullptr){return-1;}templateTtest(typenameenable_if::value,void*>::type=n

c++ - "error: no matching function for call to"

我当时在键盘上,我正在尝试使用C++来提高我的技能。我以前从未使用过模板,所以我尝试研究如何使用它们。下面的代码是结果,不幸的是,它不起作用。我确实尝试寻找问题的解决方案,但由于我没有太多使用模板的经验,所以我无法在我的问题和其他问题之间建立任何联系。所以,我决定寻求帮助。templateclassVector2{public:Ax,y;Vector2(Axp,Ayp){this->x=xp;this->y=yp;}};templateclassrayToCast{public:rayToCast(Bangle,Vector2origin,Vector2point1,Vector2po

C# 到 C++11 的转换 : delegate templates

我正在尝试将此C#代码转换为C++:publicdelegatevoidAction(Tobj);publicdelegatevoidAction(T1arg1,T2arg2);publicdelegatevoidAction(T1arg1,T2arg2,T3arg3);很明显这调用了std::function。由于这是一个更大的项目,我使用了一个工具来完成所有的转换,这就是它得出的结果:#includetemplate//C#TOC++CONVERTERTODOTASK:C++doesnotallowspecifyingcovarianceorcontravarianceinagen

c++ - 嵌套命名空间 : where should default template arguments go? 中模板类的前向声明

我在嵌套命名空间中有一个模板类的前向声明namespacen1{namespacen2{templatestructA;}usingn2::A;}接着是一个定义,实际上它在不同的文件中,中间有一些东西:structX{};namespacen1{namespacen2{templatestructA{};}usingn2::A;}那么以下总是可以的:n1::n2::Aa;但是这个捷径n1::Aa;在clang中给出编译错误error:toofewtemplateargumentsforclasstemplate'A'除非我删除前向声明;g++两者都接受。clang似乎保留在第一个不包含

c++ - 为什么 regex_match 抛出 "complexity exception"?

我正在尝试测试(使用boost::regex)文件中的一行是否仅包含由空格分隔的数字条目。我遇到了一个我不明白的异常(见下文)。如果有人能解释为什么抛出它,那就太好了。也许我在这里以定义模式的方式做了一些愚蠢的事情?这是代码://regex_test.cpp#include#include#includeusingnamespacestd;usingnamespaceboost;intmain(){//Mybasicpatterntotestforasinglenumericexpressionconststringnumeric_value_pattern="(?:-|\\+)?[[