Boost logo

Boost Users :

From: Douglas Gregor (gregod_at_[hidden])
Date: 2003-11-06 19:19:34


On Tuesday 04 November 2003 08:47 pm, Angus Leeming wrote:
> I'm having some problems with bind and wonder if someone might help.
[snip code]
> boost/boost-1.30.2/boost/function/function_template.hpp:117: could not
> convert `f->boost::_bi::bind_t<R, F, L>::operator()(A1&) [with A1 = size_t,
> R = const Node&, F = boost::_mfi::cmf1<const Node&, FEM, unsigned int>, L =
> boost::_bi::list2<boost::reference_wrapper<FEM>, boost::arg<1> >]((&a0))'
> to `Node&'

How odd. I would have expected it to be ambiguous at the call to bind, but it
takes the const version over the non-const version.

> Is there a fix for this or have I hit a brick wall?

Well, you're stuck casting the member function pointer to the right type:

       boost::function1<Node &, size_t> get_node =
                boost::bind((Node& (FEM::*)(FEM::size_type))&FEM::node,
                            boost::ref(fem), _1);

> Second question. I'd like to combine these two boost::functions into
> a single
> boost::function2<void, size_t, double> all_in_one = ...;
> all_in_one(i, val);
> but I'm getting horribly lost trying to determine the '...'.
> Is it possible? Any clues?

Ah, the beauty of nesting bind() expressions. Start with the outer call
(set_conc), and work your way inward by writing the parameters to it. Here's
the final solution (with ugly casting hack):

        boost::function2<void, size_t, double> all_in_one =
          boost::bind(&Node::set_conc,
                      boost::bind((Node& (FEM::*)(FEM::size_type))&FEM::node,
                                  boost::ref(fem),
                                  _1),
                      _2);

        Doug


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net