Using boost::bind with boost::function: retrieve binded variable type

后端 未结 4 701
自闭症患者
自闭症患者 2020-12-21 04:14

Is there any way to retrieve information on what paramaters were bounded by boost::bind or does this need to be stored manually?

i.e.:

in .h

         


        
4条回答
  •  太阳男子
    2020-12-21 04:52

    Your basic problems seems to be that your interface isn't rich enough. Once you are done adding things to your vector (and thus start only using your function objects polymorphically), you should not need to look at their concrete types again. There are several ways to solve this:

    Use an additional callback that stores the parsing function:

    vector myParseVector;
    myParseVector.push_back(boost::bind(&MyClass::parseInt, this, MyClass::_myint);
    myParseVector.push_back(boost::bind(&MyClass::parseDouble, this, MyClass::_mydouble);
    

    ..or, of course, put these two callbacks into the same vector via a custom struct or a pair.

    Or... use type-erasure yourself with custom made interface that supports parse and execute!

提交回复
热议问题