Boost logo

Boost Users :

From: Rodolfo Federico Gamarra (rgamarra_at_[hidden])
Date: 2008-08-31 22:45:33


Hello Boost users,

I'm working on my thesis with the Boost library (Boost-1.34.1) running on
g++ (GCC) 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2).

What I'm trying to do can be done very simply, but I preferred to do it more
appropriately, I believe, using the Boost Min-Max library. I'm trying to
simultaneously obtain the maximum and minimum values of a member function
call over a lists of objects.

Suppose there exists a
    class utl::Particle;
with a member function
    double GetEnergy() const;

In a member field of another class I have a list of those particles
    std::list<utl::Particle> particles;
for which I want min/max GetEnergy() values.

How is that accomplished using Boost.Min-Max?

Below I give some excerpts of some of the things I've tried, but didn't
work. In order to try to understand what I was doing I split the code over
several lines, so to minimize the non-compiling one. In both cases the error
seems to be (that line is what I believe to be the most important part of
all the error messages):

boost/iterator/iterator_adaptor.hpp:353: error: no match for 'operator-'
in...

First attempt:
    boost::function<double(const utl::Particle&)> energy =
boost::lambda::bind(&utl::Particle::GetEnergy, boost::lambda::_1 );
    boost::transform_iterator< boost::function<double(const utl::Particle&)>
, list<utl::Particle>::const_iterator>
        itBeg(particles.begin(), energy),itEnd(particles.end(), energy);
    boost::minmax(itBeg, itEnd); // This call doesn't compile.

Second attempt:
    boost::function<double(const utl::Particle&)> energy =
boost::lambda::bind(&utl::Particle::GetEnergy, boost::lambda::_1 ); // As in
the first case.
      boost::minmax(
          boost::make_transform_iterator(particles.begin(),energy ),
          boost::make_transform_iterator(particles.end() ,energy )); //
This call doesn't compile.

Thanks a lot for your help.

-- 
Rodolfo Federico Gamarra


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