It’s difficult to make reference-counting implementations thread safe. (See Herb Sutter, More Exceptional C++, pp. 104–14). See Chapter 10 for more on programming with multiple threads.
It is tempting to use mathematics here to factor out some of these calls to erase( ), but since in some cases one of the operands is string::npos (the largest unsigned integer available), integer overflow occurs and wrecks the algorithm.
Alert: For the safety reasons mentioned, the C++ Standards Committee is considering a proposal to redefine string::operator[] to behave identically to string::at() for C++0x.
Your implementation can define all three template arguments here. Because the last two template parameters have default arguments, such a declaration is equivalent to what we show here.
Beware that some versions of Microsoft Word erroneously replace single quote characters with an extended ASCII character when you save a document as text, which of course causes a compile error. We have no idea why this happens. Just replace the character manually with an apostrophe.
POSIX, an IEEE standard, stands for "Portable Operating System Interface" and is a generalization of many of the low-level system calls found in UNIX systems.
It is customary to use operator void*( ) in preference to operator bool( ) because the implicit conversions from bool to int may cause surprises, should you errantly place a stream in a context where an integer conversion can be applied. The operator void*( ) function will only implicitly be called in the body of a Boolean expression.
A more in-depth treatment of stream buffers and streams in general can be found in Langer & Kreft’s, Standard C++ IOStreams and Locales, Addison-Wesley, 1999.
For more information on machine epsilon and floating-point computation in general, see Chuck’s article, "The Standard C Library, Part 3", C/C++ Users Journal, March 1995, also available at www.freshsources.com/1995006a.htm.
The C++ standards committee is considering relaxing the only-within-a-template rule for these disambiguation hints, and some compilers are allowing then in non-template code already.
Technically, comparing two pointers not inside the same array is undefined behavior, but compilers nowadays don’t complain about this. All the more reason to do it right.
Also called Koenig lookup, after Andrew Koenig, who first proposed the technique to the C++ standards committee. ADL applies universally, whether templates are involved or not.