boost-bind

boost::bind and insert of a boost::unordered_map

这一生的挚爱 提交于 2020-01-03 04:57:06
问题 I want to use boost::bind to create a boost::function inserting a new key-value pair into a boost::unoredered_map but I got few compilation errors. typedef boost::unordered_map< std::string, std::string > dict_type; inline void insert( const std::string& key, const std::string& value ){ typedef std::pair<dict_type::iterator, bool> out_type; dict_type::value_type to_insert(key,value); boost::function<void()> f = boost::bind<out_type>( &dict_type::insert ,obj_ ,boost::cref(to_insert) ); } The

Is it possible to attach an action to a boost::spirit::rule parser which assigns the parsed result to a member of a (yet) unknown instance?

一曲冷凌霜 提交于 2020-01-02 07:12:23
问题 I'm trying to reference a member of a (yet) unknown instance from within a boost::spirit rule definitions' action, so in pseudocode, instead of double_[ref(rN) = _1] I'm looking for something like X** ppx; double_[ref(&X::rN, ppx) = _1] A workaround for it could be a simple "semantic action" with a parameter which knows the instance and would be able to write to it, like qi::rule<Iterator, Skipper> start; my_grammar(DataContext*& dataContext) : my_grammar::base_type(start) , execContext

Is it possible to attach an action to a boost::spirit::rule parser which assigns the parsed result to a member of a (yet) unknown instance?

巧了我就是萌 提交于 2020-01-02 07:12:21
问题 I'm trying to reference a member of a (yet) unknown instance from within a boost::spirit rule definitions' action, so in pseudocode, instead of double_[ref(rN) = _1] I'm looking for something like X** ppx; double_[ref(&X::rN, ppx) = _1] A workaround for it could be a simple "semantic action" with a parameter which knows the instance and would be able to write to it, like qi::rule<Iterator, Skipper> start; my_grammar(DataContext*& dataContext) : my_grammar::base_type(start) , execContext

How can I use boost::bind to bind a class member function?

独自空忆成欢 提交于 2020-01-02 03:46:04
问题 #include <QtCore/QCoreApplication> #include <boost/bind.hpp> #include <boost/function.hpp> class button { public: boost::function<void()> onClick; boost::function<void(int ,double )> onClick2; }; class player { public: void play(int i,double o){} void stop(){} }; button playButton, stopButton; player thePlayer; void connect() { //error C2298: 'return' : illegal operation on pointer to member function expression playButton.onClick2 = boost::bind(&player::play, &thePlayer); stopButton.onClick =

Error using boost::bind for subscribe callback

ぃ、小莉子 提交于 2020-01-01 15:32:14
问题 We're getting this compile error followed by many more errors showing attempts to match the subscribe parameters to all possible candidate functions when using boost::bind as a callback for subscribe. error: no matching function for call to ‘ros::NodeHandle::subscribe(const char [18], int, boost::_bi::bind_t<void, void (*)(const geometry_msgs::WrenchStamped_<std::allocator<void> >&, moveit::planning_interface::MoveGroup&), boost::_bi::list2<boost::arg<1>, boost::_bi::value<moveit::planning

boost::bind with functions that have parameters that are references

混江龙づ霸主 提交于 2020-01-01 01:11:29
问题 I noticed that when passing reference parameters to boost bind, those parameters won't act like references. Instead boost creates another copy of the member and the original passed in variable remains unchanged. When I change the references to pointers, everything works ok. My question is: Is it possible to get references to work, or at least give a compiling error when it tries to use reference parameters? 回答1: The boost documentation for bind suggests that you can use boost::ref and boost:

boost::bind, std::bind and overloaded functions

余生长醉 提交于 2019-12-31 03:39:14
问题 I noticed that boost::bind, unlike std::bind, can work with overloaded functions when one of these functions doesn't have any parameters. Am I right? Is this documented? #include <boost/bind.hpp> #include <functional> #include <iostream> void foo() { std::cout << "::foo() \n"; } void foo(int) { std::cout << "::foo(int) \n"; } int main() { boost::bind(foo)(); // Ok boost::bind(foo, 0)(); // Ok // std::bind(foo)(); // Error // std::bind(foo, 0)(); // Error } #include <boost/bind.hpp> #include

Perform argument substitution on nested boost::bind without composition

若如初见. 提交于 2019-12-30 05:16:30
问题 Suppose I have a function which takes a nullary functor as an argument: void enqueue( boost::function<void()> & functor ); I have another function which takes an int and does something internally: void foo( int a); I would like to nest, but not compose, these together so that I get a functor with the signature: boost::function<void(int)> functor Which when called with a value - say 4 - performs the following: enqueue( boost::bind(&foo, 4) ) My first attempt was the following: boost::function

About shared_ptr and pointer to member operator `->*` and `std::bind`

醉酒当歌 提交于 2019-12-29 06:17:31
问题 Recently I discovered that shared_ptr does not have pointer to member operator ->* . I created simple example: template <typename Pointer, typename Function, typename... Args> auto invoke1(Pointer p, Function f, Args... args) -> decltype((p->*f)(args...)) { return (p->*f)(args...); } struct A { void g() { std::cout << "A::g()\n"; } }; int main() { A a; invoke1(&a, &A::g); // works!! std::shared_ptr<A> sa = std::make_shared<A>(); invoke1(sa, &A::g); // compile error!! } Q1: Why is so? Why

What is the return type of boost::bind?

為{幸葍}努か 提交于 2019-12-28 04:22:29
问题 I want to save the "binder" of a function to a variable, to use it repetitively in the following code by exploiting its operator overloading facilities. Here is the code that actually does what I want: #include <boost/bind.hpp> #include <vector> #include <algorithm> #include <iostream> class X { int n; public: X(int i):n(i){} int GetN(){return n;} }; int main() { using namespace std; using namespace boost; X arr[] = {X(13),X(-13),X(42),X(13),X(-42)}; vector<X> vec(arr,arr+sizeof(arr)/sizeof(X