From: Douglas Gregor (dgregor_at_[hidden])
Date: 2007-06-14 11:36:58
Arkadiy Vertleyb wrote:
> One example:
> The library author defines a main template;
> The users A and B provide specializations for their classes;
> One TU includes the library header, and the header A;
> Another TU includes the library header, the header A, and B.
> Now the template is defined differently in different TUs.
That's fine, so long as the template is not instantiated differently in
different translation units. The ODR is about the actual use of
inconsistent definitions. If someone instantiations the primary template
with a class from A in one TU, and then in another TU instantiations the
same template with the same class from A, but this time picks up a
specialization, then we have an ODR violation. Merely the presence of an
unused specialization does not cause an ODR violation.
> Another example (from the Typeof library):
> Types and templates are mapped to unique numbers using preprocessor counter.
> The resulting specializations depend on the order these specializations are
> seen by the preprocessor, and therefore on the order of inclusion.
The Typeof library is a great thing, but the techniques needed to
simulate what should be a language feature are C++ hacks. We don't need
to loosen or fix the ODR, we need the functionality that the Typeof
library provides ("give me the type of this expression!") to be in the
language. decltype fixes that.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk