草庐IT

mobx-miniprogram-bindings

全部标签

c++ - tr1::mem_fn 和 tr1::bind:常量正确性和重载

以下代码片段有什么问题?#include#include#includeusingnamespacestd::tr1::placeholders;structabc{typedefvoidresult_type;voidhello(int){std::cout尝试用g++-4.3编译它,似乎cv-qualifier重载函数混淆了tr1::mem_fn和tr1::bind并出现以下错误:nomatchingfunctionforcallto‘bind(,...下面的代码片段编译但似乎破坏了const-correctness:structabc{typedefvoidresult_type

c++ - 从模板中绑定(bind)模板函数

接续thisquestion.我正在尝试绑定(bind)一个给定的函数,该函数返回除void之外的其他内容,以便稍后能够简单地调用f()。但是,以下代码无法在GCC4.4上编译。它在VS2010上编译,但生成的程序崩溃。templatevoid_hideRet(std::functionfunc,RetType*ret){*ret=func();}templatestd::functionregisterFunc(FuncTypefunc,RetType*ret,ParamTypeparam){autof=std::bind(func,std::forward(param));retu

c++ - 使用带有绑定(bind)的 boost 字符串算法谓词

编译这个例子#include#include#include#include#includeusingnamespacestd;intmain(int,char**){vectortest;test.push_back("xtest2");test.push_back("test3");ostream_iteratorout_it(cout,"\n");remove_copy_if(test.begin(),test.end(),out_it,boost::bind(boost::algorithm::starts_with,_1,"x"));}因错误而失败nomatchingfunc

c++ - 没有模板重新绑定(bind)的 typedef 模板。作为模板类参数的模板使用

我想做这样的事情:templateclassBaseSubscriber{};templateclassBasePublisher{//notworking:invaliduseoftemplate-name'BaseSubscriber'withoutanargumentlisttypedefBaseSubscriberSubscriberType;//compilingtypedefBaseSubscriberSubscriberTypeT;};templateclassSubscriber,classData>classClassA:publicSubscriber{};temp

c++ - 如何将绑定(bind)与通过引用传递的抽象类结合使用

我正在尝试使用std::transform和std::bind来简化循环。这是一些代码:classITest{public:virtualCPruebaPrueba(doublep,doubled=0)const=0;};voidfoo(constITest&test){std::vectorv;std::vectorvRes;//...//...std::transform(v.begin(),v.end(),back_inserter(vRes),bind(&ITest::Prueba,test,_1,0));//...}这不会编译。我正在使用VS2008SP1,我遇到了很多我不理

c++ - 使用 boost::lambda::bind 有什么问题?

我正在尝试使用boost::lambda::bind()定义一个谓词,我将其传递给Boost.Range中的find_if算法。具体来说,我想搜索结构vector以找到特定成员具有指定值的第一个条目。我的例子如下:#include#include#includeusingnamespacestd;usingnamespaceboost;usingnamespaceboost::lambda;structfoo{strings;intx;};intmain(){//createlistandaddacoupleentriesvectorfooList;foof1={"abc",1};fo

c++ - 从零开始的 Lua/C++ 绑定(bind)

我是Lua的新手,正在尝试了解一些基础知识。我想了解的是将Lua绑定(bind)到C++实例。我对第三方库不感兴趣,我想在更基础的层面上理解这一点-谢谢:)这是我的问题:根据我所阅读的内容,我的假设是Lua只能绑定(bind)到静态C函数。这是正确的吗?这是否意味着要绑定(bind)C++类的实例,我首先需要为我想要的每个方法和属性getter/setter编写静态函数,并接受实例指针作为参数。我会在Lua中注册这些函数。我会向Lua传递一个指向C++类实例的指针。我会从Lua调用其中一个注册函数,传递C++实例指针。静态函数取消引用指针,调用等效方法。这有意义吗?还是我弄错了什么?感

c++ - 如何将可变参数模板参数绑定(bind)到函数

我正在尝试模仿std::thread构造函数的功能:templateexplicitthread(Function&&f,Args&&...args);我试过使用调试器单步执行以查看它是如何工作的,但我无法弄明白。如何像线程的构造函数那样创建和存储绑定(bind)类型?像这样(语法可能有误):classmyClass{private:autobindType;public:templateexplicitmyClass(Function&&f,Args&&...args):bindType(somehowBind(f,args){}voidevaluate(){bindType();}

c++ - 在通过在 main 中声明数组来解决之前,数组绑定(bind)不是整数常量

程序1#includestd::size_tthree(){return3;}inti[three()];intmain(){return0;}方案二std::size_tthree(){return3;}intmain(){inti[three()];return0;}这里的问题是程序1如预期的那样给出了编译错误"error:arrayboundisnotanintegerconstantbefore']'token"但是不知道为什么程序2编译成功了? 最佳答案 C99允许inti[three()];声明一个变长数组,但只允许if

c++ - 在模板模板参数中抛出多模板类 - 模板绑定(bind)?

给定以下类:templateclassB>classA{Bb;};我现在可以写这样的代码了:Aa1;Aa2;将除一个参数外所有参数都指定的多参数类放入B中的最优雅方法是什么?像带有int-keys的map?我唯一能想到的是:templateusingC=MyMap;A>a3;是否有这样一个模板等同于std::bind,我们可以只提供一部分参数并保留其中一个参数?我很确定该语言没有提供此功能,但人们之前一定已经解决了这个问题。A>a3; 最佳答案 没有与std::bind等效的内置模板,但您可以自己编写一个。这是一个简单的版本,它绑定