Boost logo

Boost Users :

From: Angus Leeming (angus.leeming_at_[hidden])
Date: 2003-11-04 20:47:59


I'm having some problems with bind and wonder if someone might help.

The attached file compiles and runs fine when compiled with boost-1.30.2
(g++ 3.2 on a PC and g++ 3.3 on a Dec Alpha, both running linux).

However, compilation fails if I uncomment the overloaded 'node'
member function below.

struct FEM {
        typedef std::vector<Node>::size_type size_type;

        FEM(std::vector<Node> const & nodes) : nodes_(nodes) {}

        size_type nnodes() const { return nodes_.size(); }
        Node & node(size_type i) { return nodes_[i]; }
// Node const & node(size_type i) const { return nodes_[i]; }

private:
        std::vector<Node> nodes_;
};

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&'

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

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?

Kind regards,
Angus

ps. What is the prefered way of posting code? Inline or as an attachment?
A
        std::vector<Node> nodes(10);
        FEM fem(nodes);

        size_t i = 5;
        double const val = 14;

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

        boost::function1<void, double> set_value =
                boost::bind(&Node::set_conc, boost::ref(get_node(i)), _1);

        set_value(val);




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