Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-11-22 13:28:41


Terry G wrote:
> Here's another (simplified) program I can't get to work.
> I'm trying to write a generic routine that finds the largest element
> of a sequence.
> It is assumed that element->size() is defined, as it is for
> boost::array and std::string.
> For some reason, the Largest template function works okay for
> std::strings, but not for boost::arrays.
> Can you tell me what is wrong?

This is a bug in boost::array, its size() function is static. You can remove
the 'static' in your local copy and make it

    size_type size() const;

to match TR1 and the future C++ standard.

> template <class InIter>
> InIter Largest(InIter first, InIter last) {
> typedef typename boost::pointee<InIter>::type ObjType;
> InIter largest = std::max_element(first, last,
> boost::bind(std::less<std::size_t>(),
> boost::bind(&ObjType::size, _1),

Here: the problem is that &ObjType::size takes no arguments when ObjType is
boost::array.

> boost::bind(&ObjType::size, _2))
> );

You can rewrite this as

boost::bind(&ObjType::size, _1) < boost::bind(&ObjType::size, _2)

BTW.

> return largest;
> } // Largest


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