boost-bind

Am I reinventing the wheel with this trivial method call forwarding class?

心已入冬 提交于 2019-12-06 03:53:57
问题 I just found myself creating a class template <typename T> struct invoker { void operator()(T& it) const {it();} }; so I could pass an invoker<foo> to something (which isn't under my control) which wants to call invoker<foo>::operator()(foo&) on it repeatedly with different foo instances, to get it to forward those calls to the foo 's foo::operator()() method. I know it's only a few lines, but this seems like the sort of thing which is probably already provided for by STL's functional, or

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?

扶醉桌前 提交于 2019-12-06 01:25:45
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(execContext) { start = qi::double_[ boost::bind(&my_grammar::newValueForXY, dataContext, ::_1) ]; However, I

How can I search a container of objects for a data member value?

喜夏-厌秋 提交于 2019-12-05 20:42:05
I have an object type like this: struct T { int x; bool y; }; and a container of them like this: std::vector<T> v; and a burning desire to determine — in a single statement — whether any of the elements of v have y == true . This likely involves std::find_if . My understanding is that std::bind and boost::bind are for member functions and cannot be applied to member data. Because I dislike them, I wish to avoid: comparison functions/functors loops Because my environment is C++03, the following are not available: lambdas Lightness Races with Monica My understanding is that std::bind and boost:

std::stringstream as parameter to a function

拥有回忆 提交于 2019-12-05 19:24:08
I have a std::vector<std::string> temp_results and I wish to use std::for_each to go through this vector and concatenate a string, so I concocted the following construction: std::stringstream ss; std::string res = std::for_each(temp_results.begin(), temp_results.end(), boost::bind(addup, _1, ss)); std::string addup(std::string str, std::stringstream ss) { ss << str; ss << ";"; return ss.str; } I get the following error, which is beyond my understanding: error C2475: 'std::basic_stringstream<_Elem,_Traits,_Alloc>::str' : forming a pointer-to-member requires explicit use of the address-of

How do you declare an extern “C” function pointer

落爺英雄遲暮 提交于 2019-12-05 17:34:30
问题 So I have this code: #include "boost_bind.h" #include <math.h> #include <vector> #include <algorithm> double foo(double num, double (*func)(double)) { return 65.4; } int main(int argc, char** argv) { std::vector<double> vec; vec.push_back(5.0); vec.push_back(6.0); std::transform(vec.begin(), vec.end(), vec.begin(), boost::bind(foo, _1, log)); } And receive this error: return unwrapper<F>::unwrap(f, 0)(a[base_type::a1_], a[base_type::a2_]); .....................................................

Is it possible to create a function pointer to the a function's `new` operator/constructor?

允我心安 提交于 2019-12-05 10:55:22
If I were to wanted to parameterize creating an object, I could of course make a function which called new on a particular class and passed out a pointer. I am wondering if it's possible to skip that step and pass a function pointer to the new operator itself. boost::lambda provides function wrappers for new and delete . These can be used to easily convert an new call into a function object. operator new (as well as the other flavours) takes care of allocating memory but does not construct objects. In fact its return type is void* . What constructs an object is a new expression , which is part

C ++ Boost Bind Performance

早过忘川 提交于 2019-12-05 07:12:16
Are there any performance impacts (positive or negative) when binding functions (using Boost Bind) ? Maybe, may not be. It depends. The result of std::bind (or also boost::bind ) is a so-called "bind expression", which has an un­know­able type determined by the implementation. This type is a Callable , and it is convertible to an in­stance of std::function (or boost::function ). Internally, function (may) use type erasure to handle various complex, stateful "call­able objects". This entails a dynamic allocation and a virtual dispatch in some (though not neces­sari­ly all) cases. Both bind and

How to parse a mathematical expression with boost::spirit and bind it to a function

こ雲淡風輕ζ 提交于 2019-12-05 04:28:50
问题 I would like to define a function taking 2 arguments double func(double t, double x); where the actual implementation is read from an external text file. For example, specifying in the text file function = x*t; the function should implement the multiplication between x and t , so that it could be called at a later stage. I'm trying to parse the function using boost::spirit. But I do not know how to actually achieve it. Below, I created a simple function that implements the multiplication. I

How do you pass boost::bind objects to a function?

我的未来我决定 提交于 2019-12-05 00:45:42
I have a one-dimensional function minimizer. Right now I'm passing it function pointers. However many functions have multiple parameters, some of which are held fixed. I have implemented this using functors like so template <class T> minimize(T &f) { } Functor f(param1, param2); minimize<Functor>(f); However the functor definition has lots of crud. Boost::bind looks cleaner. So that I could do: minimize(boost:bind(f,_1,param1,param2)) However I'm not clear what my minimize declaration should like like using boost::bind . What type of object is boost::bind ? Is there an easy pattern for this

Error using boost::bind for subscribe callback

我们两清 提交于 2019-12-04 14:07:53
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_interface::MoveGroup*> > >)’ Our code is as follows. The commented lines show the code which works when