Re: BinaryPredicate Question
Otis Bricker wrote:
I'm trying to figure out is the following technique is valid.
Given
std::vector<DataItem> cache;
which is sorted by the ID_ field of each DataItem.
And this Predicate class:
class IdLessThan: public std::binary_function<long, DataItem, bool>
{
public:
bool operator()
( long lhs, const DataItem& rhs)const{return lhs <
rhs.ID_;};
};
Is the following valid?
Vector<DataItem>::iterator it =
std::upper_bound(cache.begin(),cache.end(),ID, IdLessThan());
No. Given this call, IdLessThan must be callable with a first
argument of type DataItem, and a second of type long (and the
reverse).
I ask because the compiler I am using is unable to compile the debug
build of this. It seems to be trying to test the predicate by calling:
IdLessThan::operator()(const DataItem& lhs,long rhs);
Is this version required or is it just a case of a debug version
requiring it for 'testing', which I believe can be disabled?
It's required. It is, in fact, the only version required.
And would it be a good idea to include the extra form to allow the
testing by the debug build?
Generally, if you can't build the debug version, it's best to
suppose that the production version won't work correctly anyway.
(In this case, I'd be surprised if you could build any version.)
--
James Kanze (Gabi Software) email: james.kanze@gmail.com
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]