Boost logo

Boost Users :

From: Robert Ramey (ramey_at_[hidden])
Date: 2005-02-08 18:37:40


Thinking about this just a little bit - I realize that my intention may not
have been the same as some others.

BOOST_STRONG_TYPEDEF(long, HBLA);
HBLA h;

I wanted h to work everywhere the same as a long except that it has a
distinguishable type that can be used for specialization of templates. So I
envisioned that

bool b = h;

    would be just as legal as

bool b = long;

is. I had no intention of "fixing up" C++ conversions. I just wanted a
wrapper to permit variables to be distinquished. So BOOST_STRONG_TYPE
includes automatic conversions to implement this.

Now, the question of whether b = h should be trapped and an error is a
different one in my opinion. I think the recent discussions on a dimensions
library is relevant here.

I believe that typedef as currently implemented is ill-concieved and
suggests the creation of a new type when in fact it does no such thing. So
I do think BOOST_STRONG_TYPE should be promoted to a first class boost
object. If someone want's to do this, I'm all for it. I suspect that my
implementation isn't complete enough (though it might be) and there are
probably some subtlties that have to be discovered and and documented. So I
would encourage an effort to refine and improve this.

Robert Ramey

gast128 wrote:
> Dear all,
>
> I was playing with the serialization library, and ran into the
> BOOST_STRONG_TYPEDEF. In our own development environment we have a
> similar feature based on the article 'True typedefs' from Matthew
> Wilson (CUJ march 2003):
>
> BOOST_STRONG_TYPEDEF(long, HBLA);
> BOOST_STRONG_TYPEDEF(long, HBLUB);
>
> HBLABLA hBla(1);
> HBLUB hBlub(3);
> bool bOk = false;
>
> bOk = (hBlub == hBla); //rejected if base types are different
> bOk = (hBlub != hBla); //does not compile on VC 7.1
> bOk = (hBlub < hBla); //rejected if base types are different
>
> hBlub = hBla; //accepted by boost_strong_typedef, this is a
> deliberate choice
>
> So I guess one can discuss about some behavior.
>
> But perhaps if it supports '==', it should also support '!='?
>
> Wkr,
> me


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net