Pelle Beckman wrote:
[color=blue][color=green]
> > Where are the unit tests?[/color]
>
> I'll guess you'll laugh you head off...
>
> I don't know.
> What's a unit test?[/color]
Google for it.
Contrary to Howard's laugh, tests are a design thing. In the big C++ shops,
a request for a code review shall be accompanied by tests.
Here's one for your thing (with made-up code):
struct Foo{};
TEST_(TestCase, singular)
{
Singleton<Foo> mysingleton;
Singleton<Foo> yoursingleton;
Foo * p1 = mysingleton ();
Foo * p2 = yoursingleton.Instance ();
CHECK_EQUAL(p1, p2);
}
That test shows the Foo really is singular; the system did not allocate two
of them, at different addresses.
One runs all tests after every few edits. If a test fails, you have the
option to either hit Undo until they all pass, or you can debug. Without
tests, you don't know as soon as possible when you broke something, and you
can't use Undo. The only choice is to debug.
Now about style, if your system either throws an exception if new Foo fails,
then your operators can never return NULL. So maybe your system should
return a reference. Always use references without a reason to use pointers.
--
Phlip
http://www.c2.com/cgi/wiki?ZeekLand