Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost.lambda: how to sort this vector with function?
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-02-09 10:49:18


AMDG

Joost Kraaijeveld wrote:
> I want to sort a vector of Edges according to their remaining estimated
> distance to the finish point (an own implementation of a graph
> algorithm).
>
> How do I sort this vector with edges:
>
> // Returns the cost between start and finish, given a graph
> int CostEstimate( const Graph& aGraph, const Vertex& start, const Vertex& finish)
> ...
>
> // Member function of a graph
> std::vector< Edge > v = ...;
> // Sort them according to the cost
> std::sort( v.begin(),
> v.end(),
> boost::lambda::bind( CostEstimate( (*this),
> boost::lambda::bind( &Edge::otherSide, &start, boost::lambda::_1),
> finish))
> <
> boost::lambda::bind( CostEstimate( (*this),
> boost::lambda::bind( &Edge::otherSide, &start, boost::lambda::_2),
> finish)));
>

The outer bind should be

boost::lambda::bind( CostEstimate, boost::lambda::var(*this),
                                boost::lambda::bind( &Edge::otherSide, &start, boost::lambda::_1),
                                finish)

In Christ,
Steven Watanabe


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