Boost logo

Boost :

Subject: Re: [boost] Boost.Conversion review
From: John Bytheway (jbytheway+boost_at_[hidden])
Date: 2011-08-16 17:29:39


On 16/08/11 15:59, Gordon Woodhull wrote:
> Hi all,
>
> The review of Vicente Botet Escriba's Conversion library starts this
> Saturday August 20 and continues through August 29.
>
> This library provides a general system for type-to-type conversion.
> As such, it can be thought of either as a substitute for overloading
> static_cast, or as an alternative to lexical_cast when the
> intermediate conversion to text is not wanted.
>
> Your review and/or discussion would be greatly appreciated. As
> always, please post to the main Boost list if possible, or the
> boost-users list, or you can send your review directly to the Review
> Managers.

The primary concern I always have with libraries such as this one is
that they promote ODR violations. In particular, consider:

library A defines type TA

library B defines type TB

library C defines a conversion from TA to TB

library D defines a conversion from TA to TB

Now libraries C and D are incompatible; they cannot both be used in the
same program without ODR violation.

This means, if I am writing a library, then I cannot safely define a
conversion between types both of which are not in my library, because it
would make my library incompatible with any other library that also
defines such a conversion.

But, on the other hand, if one of the types *is* in my library, then I
can probably make do with a conversion constructor or conversion
operator (except perhaps if I want an explicit conversion operator and
want to support compilers without those).

So, as I see it, conversions can only be defined in two situations:

- When writing non-library code (i.e. code that will not be combined
with other code over which the author has no control).

- As a stop-gap substitute for explicit conversion operators.

Is it indeed intended only to allow conversions to be defined in these
limited circumstances? If so, then the documentation should state that
clearly. If not, how do you intend to avoid ODR violations?

John Bytheway


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