Boost logo

Boost :

From: Jody Hagins (jody-boost-011304_at_[hidden])
Date: 2007-04-12 13:26:38


On Thu, 12 Apr 2007 11:46:03 -0500
"Michael Marcin" <mmarcin_at_[hidden]> wrote:

> What's the purpose of something like:
>
> template <typename T, std::size_t N>
> struct tag_of<boost::array<T, N> >;

It forward declares a template. The compiler now knows what to expect.

> shouldn't it be something like:
>
> template <typename T, std::size_t N>
> struct tag_of<boost::array<T, N> > {};

Now you have defined the template. All non specialized stucts tag_of
will be defined as an empty class. By simply declaring it, the onus is
now on another piece of code to properly define the template. Someone
can still provide a "general" definition, but it's very possible that
specializations are the true desire.

If you want an empty stuct to be the default template, then you can use
the above. If, however, you want to force the template definitions then
simply provide the forward declaration.

With the forward declaration, if a user tries to use the struct in a
non-specialized way, a compiler error will result, which is good. You
don't want the user to get default "nothing" behavior from a typo.

Does that make any sense at all?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk