utils

© 2006,2014 John Abbott
GNU Free Documentation License, Version 1.2



CoCoALib Documentation Index

User documentation for file utils.H

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:

Maintainer documentation for files utils.H

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.

Impl of template fn MaxSquarableInteger uses GMP to compute the memorized values. A table of constants would be faster but potentially less portable (given that CoCoALib requires GMP anyway). I haven't yet found a neat way of ensuring that the type T is integral & bounded.

Bugs, Shortcomings and other ideas

Should the template function cmp require its args to be exactly the same type?

A possibly better idea for MaxSquarableInteger: precompute 2^63*sqrt(2) as unsigned long, then simply right shift this value for integral types with less than 127 bits. This suggestion presupposes a binary computer.