草庐IT

set_creation_function

全部标签

c++ - 将函数指针传递给函数时处理 <unresolved overloaded function type>

让我们考虑一下:voidgoo(){std::cout现在我想使用如下定义的一些包装函数来调用其中一个函数:templatevoidc(F&&f,A&&...a){f(std::forward(a)...);}使用方法:c(&goo,10);//(X)c(&goo);//(Y)两种情况都失败(GCC5.3.1)并出现相应的错误:error:nomatchingfunctionforcallto‘c(,int)’error:nomatchingfunctionforcallto‘c()’就我而言,失败是因为编译器在必须初始化f对象时无法选择适当的重载(信息太少)。作为一种解决方案,我当然

c++ - 无法推导 std::function 模板参数

我正在编写如下代码#includetemplatevoidfoo(conststd::function&handler){}voidgoo(constint&){}intmain(){foo([](constint&){});foo(goo);}不幸的是,由于以下错误,它拒绝在(clang6.0.0和gcc8.1.1)上编译candidatetemplateignored:couldnotmatch'function'against'(lambdaattest3.cpp:13:9)'candidatetemplateignored:couldnotmatch'function'agai

c++ - 为什么 `std::is_function_v` 没有按预期工作?

#include#include#includeusingnamespacestd;templateboolf(T&&v){returnis_function_v(v))>;}intmain(){cout输出是:(clang6.0&gcc8.0)>truefalse但我期望的结果应该是:>truetrue为什么std::is_function_v没有按预期工作? 最佳答案 您需要删除对T的引用。templateboolf(T&&v){returnis_function_v(v))>>;//~~~~~~~~~~~~~~~~~~}当se

c++ - 将 std::function 与模板一起使用

所以在最精炼的形式中,我有这样的事情发生,templateboolf(constT&a,constT&b,std::functionfunc){returnfunc(a,b);}templateboolg(constT&a,constT&b){returntrue;}但是任何调用f()的尝试,f('a','b',g),f(1,2,g),总是导致“没有匹配的函数调用‘f’”,无论我是将变量作为const引用传递还是只是普通值或其他什么。我假设它无法推断出某些模板,但我不知道在哪里或为什么。我承认,我对一般情况下如何使用函数对象的把握非常薄弱,这样做有可能吗?

c++ - 错误 : use of deleted function for overloaded template

我正在尝试模板特化,但无法确定为什么charconst*const无法在下面解析(尽管是有效类型)的原因。templateBfoo(A)=delete;templatevoidfoo(char*){}templatevoidfoo(charconst*const){}intmain(){{//typesOKcharconst*consta=nullptr;char*b=nullptr;}char*data;foo(data);//OKfoo(data);//ERRORreturn0;}错误error:useofdeletedfunction‘Bfoo(A)[withA=constcha

c++推导 "non type pointer to function"类模板参数

考虑一个模板类:templateclassProxy{voidrun(){ReturnTyperet=Fn();//...dosomething...}};//andafunctionsintfn1(){return5;}floatfn2(){return5;}这可以通过使用实例化:Proxyp1;但是显式声明返回值类型似乎是不必要的。我想要实现的是:someProxyInstantationp1;someProxyInstantationp2;不幸的是,我对c++没有任何期望,这似乎是该语言的一个隐藏角落(至少对我而言)。如果我可以从指向函数的指针获取它的类型——类似于:std::t

C++中map和set的使用

(图片来源于网络)🎈个人主页:🎈:✨✨✨初阶牛✨✨✨🐻强烈推荐优质专栏:🍔🍟🌯C++的世界(持续更新中)🐻推荐专栏1:🍔🍟🌯C语言初阶🐻推荐专栏2:🍔🍟🌯C语言进阶🔑个人信条:🌵知行合一🍉本篇简介:>:讲解C++中的新容器,set与map对于常用的接口介绍。金句分享:✨人攀明月不可得,月行却与人想随。✨目录一、set1.1set特点介绍1.2set使用1.21构造函数1.22升/降序1.23其他接口(1)**容量(`capacity`)相关:**(2)**Modifiers(修改)**(3)**查找**二、map2.1map的特点介绍2.2map的使用✨构造函数🍔[]的作用三、实例🍭两个数组的

c++ - std::binary_function - 调用不匹配?

包括#includeusingnamespacestd;intmain(){binary_functionoperations[]={plus(),minus(),multiplies(),divides()};doublea,b;intchoice;cout>a>>b;cout>choice;cout我得到的错误是:Calcy.cpp:Infunction‘intmain()’:Calcy.cpp:17:error:nomatchforcallto‘(std::binary_function)(double&,double&)’谁能解释为什么我会收到此错误以及如何消除它?

C++ 模板和 "no matching function to call"

我遇到了一个奇怪的错误。我有以下签名的功能:templatestaticboolConvertCbYCrYToRGB(constCharacteristicspace,constDATA*input,DATA*output,constintpixels){后来这样称呼:casekByte:returnConvertCbYCrYToRGB(space,(constU8*)input,(U8*)output,pixels);casekWord:returnConvertCbYCrYToRGB(space,(constU16*)input,(U16*)output,pixels);casek

c++ - boost::unordered_map -- 需要指定自定义哈希函数来散列 std::set<int> 吗?

我想使用boost::unordered_map,其中key是std::set.由于一组整数不是内置类型,我假设我必须提供我自己的散列函数(或者,更确切地说,我正在考虑使用boost'shash_range)。但是,现在我尝试像这样初始化散列映射,既不提供散列函数也不提供相等谓词——而且gcc没有提示。这里发生了什么?boost是否足够聪明,可以自行散列所有STL容器?这会比我使用自定义哈希函数慢吗?使用boost::hash_range怎么样??提前致谢。 最佳答案 根据theBoostdocumentation:thedefau