【问题标题】:Extracting argument from boost::function从 boost::function 中提取参数
【发布时间】:2016-06-20 19:58:54
【问题描述】:

我有这样的代码

int foo(int x) {
    cout<<"Argument passed x = "<<x;
    return x;
}
int main() {
    boost::function<void ()> fn = boost::bind(foo, 10);
    // can I get 10 out of fn object
    // if (fn._1 == 10) {
    //    return;
    //}
    fn();
}

我想实现一个逻辑,如果 fn - 第一个参数是 10,则不执行 fn。有可能吗?

【问题讨论】:

    标签: c++ c++11 boost boost-thread c++98


    【解决方案1】:

    boost visit_each 设施可能是门票 - 但由于它是实验性和无证我没有更多信息...

    哦,等等,我知道:这实际上是你想要的,正如 their examplecompiled and executed on ideone.com 所显示的那样。

    【讨论】:

      猜你喜欢
      • 2011-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多