|
|
The Array_set function select() selects an arbitrary element and returns a pointer to it. An overzealous interpretation of ``arbitrary'' might tempt us to return a random element. We could do this by calling random(), described in random(3C++), which returns a random pointer into an array:
const T* select()const{ check(); return (n==0 ? 0 : random(&b[0],&b[n])); }
From an efficiency standpoint, however, it is better to do as little work as possible to meet the specification. We therefore simply return the first element, if one exists:
const T* select()const{ check(); return (n==0 ? 0 : &b[0]); }