草庐IT

unary_function

全部标签

c++ - 不支持 clang 3.5 中的 -finline-functions?

我正在使用他们分发的clang3.5。我正在使用以下命令行将其安装在我的travis虚拟机中:sudoapt-add-repository'debhttp://llvm.org/apt/precise/llvm-toolchain-precise-3.5main'sudoapt-add-repository'debhttp://llvm.org/apt/precise/llvm-toolchain-precise-3.5main'当我在启用优化的情况下运行测试构建时,出现此错误:clang:error:optimizationflag'-finline-functions'isnots

c++ - 将匿名函数对象传递给 std::function?

这是我的问题:我定义了一个仿函数:classA{public:intoperator()(inta,intb)const{returna+b;}};typedeffunctionFun;然后我使用一个匿名仿函数来创建一个std::function对象,我发现了一些奇怪的东西。这是我的代码:Funf(A());f(3,4);不幸的是,这是错误的。错误信息是:error:invalidconversionfrom‘int’to‘A(*)()’[-fpermissive]error:toomanyargumentstofunction‘Funf(A(*)())’但是,当我如下更改代码时:Aa

c++ - 理解 std::function 和 std::bind

我在玩std::function和std::bind时发现一些不直观的东西,我想更好地理解它。例如:voidfun(){}voidhun(std::string){}intmain(){functiong=&fun;//Thisfailsasitshouldinmyunderstanding.functionf=std::bind(fun);//Thisworksforreasonsunknowntomefunctionh=std::bind(hun);//thisdoesn'tworkreturn0;}如何绑定(bind)function到void()函数。然后我可以调用f(1)并获

c++ - std::function 和 std::packaged_task 转换

我正在尝试移动std::packaged_task进入std::vector的std::function,因为std::packaged_task有voidoperator()(ArgTypes...args)过载,它应该可以转换为std::function,是的?这不会在MSVC和Clang上编译,MSVC提示无法将void转换为int,clang提示删除了std::packaged_task的复制构造函数|,不应移动std::vector::push_back的版本被叫到这里?这是怎么回事,这是一个错误吗?intmain(){std::vector>vec;std::package

c++ - 错误 C2064 : term does not evaluate to a function taking 0 arguments

各位!我在一个map容器中维护一组channel数据,从中可以通过channel名称访问单个channel数据。对此,我写了一个简单的函数GetIRChannelData(请看下面的代码)。编译时,语句pusIRChannelData=cit->second();抛出错误,显示为errorC2064:termdoesnotevaluatetoafunctiontaking0arguments所有要做的功能就是在map容器中搜索给定的channel名称/ID,如果找到则将其数据指针分配给时间指针。你能告诉我哪里出了问题吗?constArray2D*GetIRChannelData(std

c++ - 错误 C2280 : attempting to reference a deleted function (unique_ptr)

我检查了一些使用原始指针的旧代码,并将它们更改为unique_ptr。现在,当我尝试编译代码时,收到此错误消息:Error1errorC2280:'std::unique_ptr>::unique_ptr(conststd::unique_ptr>&)':attemptingtoreferenceadeletedfunctiond:\visualstudio2013\vc\include\xmemory0关于这种情况的编译器输出很大——为了节省这个问题的空间,请参阅here.据我所知,这与我使用唯一指针的方式有关。它从这里开始(level.h,第65-66行):typedefstd::

c++ - '&' : illegal operation on bound member function expression

这个问题在这里已经有了答案:Printaddressofvirtualmemberfunction(5个答案)关闭7年前。当我尝试从具有主要功能的单个cpp文件时,这有效,sprintf(smem_options,"#transcode{vcodec=RV24}:smem{""video-prerender-callback=%lld,""no-time-sync},",(longlongint)(intptr_t)(void*)&cbVideoPrerender);如何在类中将函数参数传递给sprintf?sprintf(smem_options,"#transcode{vcodec

c++ - 使用 std::bind 时从 std::function 获取函数指针

我正在尝试使用std::function连同std::bind,但我遇到了一些问题。这个有效:#include#includevoidprint(){std::coutfoo=print;(*foo.target())();//prints3}这在main的第二行崩溃了:#include#includevoidprint(inti){std::coutfoo=std::bind(print,2);(*foo.target())();}我真的拿着std::function并且需要能够返回函数;不只是调用它。我希望用法是这样的:#include#includevoidprint(inti)

c++ - std::is_member_function_pointer 不适用于 noexcept 成员函数

我在使用std::is_member_function_pointer时遇到问题。据我所知,在给定noexcept成员函数时它不起作用。我在标准中找不到任何声明它不适用于noexcept合格成员函数的内容。问题示例:#includeclassA{public:voidmember()noexcept{}};intmain(){//failsatcompiletimeifA::memberisadatamemberandnotafunctionstatic_assert(std::is_member_function_pointer::value,"A::memberisnotamemb

c++ - 为什么 std::function 可以用具有不同返回类型的 lambda 构造?

以下compilesfine:#includeintmain(){std::functionf=[]()->int{return1;};constint&r=f();//risadanglingreferencereturn0;}为什么可以将返回类型为constint&的std::function设置为返回类型为int的lambda?恕我直言,允许这种类型的转换在没有警告的情况下隐式发生是一个陷阱。 最佳答案 您可以使用任何可使用相关参数调用且其返回值可隐式转换为std::function返回值的对象构造一个std::functio