草庐IT

last_match

全部标签

c++ - 列表迭代器错误 : "no match for operator+" ,

对于下面的代码,我在行的标题中收到错误while((*(It2+code)).exists){voidlocatetohashtable(std::listelist,int*m,std::list&table,std::list&keylist){std::list::iteratorIt2=table.begin();inti=0;intk=0;std::list::iteratorIt;for(It=elist.begin();It!=elist.end();++It){intcode=hash_func(stringIntValue((*It).name),*m,i);whil

c++ - 在排序的 STL 容器中查找给定键的 "best matching key"

问题我有带时间戳的数据,我需要根据时间戳进行搜索,以便获得与我的输入时间戳最接近的现有时间戳。最好这应该用STL来解决。boost::*或STL::tr1::*(来自带有Featurepack的VS9)也是可能的。带时间戳的数据示例:structSTimestampedData{time_tm_timestamp;//SortingcriterionCDatam_data;//Payload}接近stl::vector,sort()和equal_range()自map或set只允许我找到完全匹配,我不会进一步使用其中之一。所以现在我有一个vector我将数据添加到其中。在搜索之前,我使

c++ - 在 libc++ 上,为什么 regex_match ("tournament", regex ("tour|to|tournament")) 失败?

在http://llvm.org/svn/llvm-project/libcxx/trunk/test/re/re.alg/re.alg.match/ecma.pass.cpp,存在以下测试:std::cmatchm;constchars[]="tournament";assert(!std::regex_match(s,m,std::regex("tour|to|tournament")));assert(m.size()==0);为什么这个匹配会失败?在VC++2012和boost上,匹配成功。在Chrome和Firefox的Javascript上,"tournament".mat

c++ - std::match_results::size 返回什么?

我对以下C++11代码有点困惑:#include#include#includeintmain(){std::stringhaystack("abcdefabcghiabc");std::regexneedle("abc");std::smatchmatches;std::regex_search(haystack,matches,needle);std::cout我希望它打印出3但我却得到了1。我错过了什么吗? 最佳答案 你得到1因为regex_search仅返回1个匹配项,size()将返回捕获组的数量+整个匹配值。你的匹配是.

c++ - gcc 和 clang 抛出 "no matching function call"但 msvc (cl) 编译并按预期工作

我写了一个小的函数模板,将不同的容器连接到一个新的容器中:#include#include#include#include#includenamespaceimpl{templatevoidjoin(OutIteratoriterator,constContainer&container,constContainers&...containers){for(constauto&item:container)*iterator++=item;join(iterator,containers...);//gccandclangcannotresolvethiscall}templatevo

c++ - 错误 : out-of-line definition of 'test' does not match any declaration in 'B<dim>'

我有一个小问题让我很烦!!我不知道下面的代码似乎有什么问题。我应该能够实现从父类(superclass)继承的功能,不是吗?但我得到error:out-of-linedefinitionof'test'doesnotmatchanydeclarationin'B'templateclassA{public:virtualdoubletest()const;};templateclassB:publicA{};templatedoubleB::test()const{return0;}我在Mac上使用clang(AppleLLVM5.1版)。 最佳答案

c++ - 为什么 "begin/end"与 "first/last"存在差异?

关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭5年前。Improvethisquestion为什么容器提供"begin"/"end"迭代器而算法需要"first"/"last"迭代器?例如:vector提供.begin()和.end()(cppreference.com,cplusplus.com)。sort需要参数first和last(cppreference.com,cplusplus.com)。编辑:发现一个更大的差异。不仅仅是算法使用“first/last”,它也是容器构

c++ - 为什么 std::sub_match<T> 公开继承自 std::pair<T, T>?

我正在阅读std::sub_match的文档并看到它公开继承自std::pair.自sub_match只是一对迭代器变成了一个字符序列,加上一些额外的功能,我可以理解它是用一个pair实现的,但为什么要使用公共(public)继承呢?从std::pair公开继承的问题与从大多数其他标准类公开继承相同:它们并不意味着要进行多态操作(特别是它们没有定义虚拟析构函数)。其他成员也将无法正常工作,即赋值运算符和交换成员函数(它们不会复制matched的sub_match成员)。为什么Boost开发人员和委员会决定实现sub_match通过公开继承pair而不是使用组合(如果他们想通过first

c++ - 为什么 std::find_if(first, last, p) 不通过引用获取谓词?

我正在查看std::find_ifoncppreference.com,的各种签名我注意到采用谓词函数的flavors似乎按值接受它:templateInputItfind_if(InputItfirst,InputItlast,UnaryPredicatep);如果我理解正确的话,具有捕获变量的lambda会为其数据的引用或拷贝分配存储空间,因此“按值传递”可能意味着为调用复制了捕获数据的拷贝。另一方面,对于函数指针等可直接寻址的东西,如果直接传递函数指针,性能应该会更好,而不是通过引用到指针(pointer-to-pointer)。首先,这是正确的吗?上面的UnaryPredica

c++ - “no match for ' operator< '” 尝试插入到 std::set 时

我正在使用gcc4.3.3尝试编译以下代码:structtestStruct{intx;inty;booloperatorsetti;setti.insert(testStruct(10,10));return0;}我得到这个错误:/usr/include/c++/4.4/bits/STL_function.h|230|错误:‘__x我怀疑我没有像应该做的那样重载运算符,但我无法查明确切的问题。我在这里做错了什么? 最佳答案 运算符必须是const并且取一个const引用:booloperator