How to use/manipulate return value from nested boost::bind

人走茶凉 提交于 2019-12-11 04:14:08

问题


I have two functions: 1. A & DataSource(); 2. void DataConsumer( A * );

What I want to achieve: Using one statement to assemble them into one functor.

I have tried:

1. boost::function< void()> func( boost::bind( DataConsumer, & boost::bind( DataSource ) ) );

certainly it didn't work, compiler says it can not convert 'boost::_bi::bind_t ' to 'A *'

2. boost::function< void()> func( boost::bind( DataConsumer, boost::addressof( boost::bind( DataSource ) ) ));

compiler says cannot convert parameter 1 from 'boost::_bi::bind_t' to 'A &'

Question: how to use return value from the nested boost::bind ? or if you want to use boost::lambda::bind.


回答1:


guys, I just found the answer, like following:

boost::function< void()> func(
        boost::bind( DataConsumer, 
                     boost::bind( boost::addressof< A >, boost::bind< A& >( DataSource ) )
                    )            );

The theory should be: since we call DataSource later, we need a functor that uses the return value later as well.



来源:https://stackoverflow.com/questions/2650614/how-to-use-manipulate-return-value-from-nested-boostbind

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!