Boost logo

Boost Users :

From: Max Motovilov (max_at_[hidden])
Date: 2006-02-15 19:44:14


I only stumbled to this problem recently, after happily using the patently
unportable solution for years (with numerous versions of STL to boot). Let's
say we have a sorted vector of complex objects with a fairly simple key, and
want to do lower_bound() on just a key, not a specially constructed instance
of the whole object. It turns out that:

bool less( const Object&, const Key& );

lower_bound( v.begin(), v.end(), Key(something), ptr_fun(less) );

is expressly prohibited by the SGI STL specifications and not quite allowed,
even though not quite prohibited either, by the ISO standard (unless my
standardese grew rusty again). It also turns out that there are STLs where
it won't work (e.g. the new Plauger's STL shipped with VStudio 2005 release,
but not beta 2...).

Now, this:

struct less {
  bool operator()( const Object&, const Key& ) const;
  bool operator()( const Key&, const Object& ) const;
};

lower_bound( v.begin(), v.end(), Key(something), less() );

should work everywhere, or so I think. Would be nice to be able to create
such an adaptor for a pair of functions (or a pair of bind or lambda
expressions for that matter). I blogged a simple solution (for functions
only) here
http://swsw.motovilov.net/weblogs/swsw/archives/2006/02/asymmetrical_pr.html
but am wondering if perhaps I missed a generic solution in one of the Boost
libraries, or there's one coming in the new release?

Any comments/suggestions?

Regards,
...Max...


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