This file defines a few very basic functions which I feel should
really be part of the standard C++. Nevertheless I have placed all
definitions inside the namespace CoCoA
. Here is a summary:
DeleteObject
struct is useful when using the C++ standard
library containers to hold plain pointers to data they own. I took
it from Scott Meyers's book "More Effective STL".
cmp
which conducts a three-way comparison of
its two arguments: cmp(a, b) returns -1 if a<b, returns 0 if a==b,
and returns 1 if a>b -- you can think of cmp(a,b) = sgn(a-b).
LexCmp3
which conducts a three-way lex
comparison of two sequences (specified by start/end iterators).
The call LexCmp3(StartA, EndA, StartB, EndB) gives the result
-1, 0, or 1 according as sequence A is lexicographically before
sequence B, equal to sequence B, or after sequence B.
Everything is in utils.H
; the functions are all so simple that they can be
implemented inline.
The type int
seemed the most natural choice for the return value of the
three-way comparison functions (though signed char
would be big enough).
The implementation assumes that operator<
is defined; this decision was
inspired by assumptions made by various STL functions. The types of the
arguments may be different as this is probably be more convenient for the
user. Obviously the generic definition given here can be overridden by
more efficient specific definitions for certain argument types.
Should the template function cmp
require its args to be exactly the same type?