BOOST_STRONG_TYPEDEF

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

I needed this facility for the serialization system. I couldn't find it
anywhere so I implemented my own version. I worked on it just enough to
make it adequate for my purposes. I'm sure it could be improved. I ran
into annoying problems in that it generated a lot of syntax errors with
borland compilers. On some gcc versions it issues warnings - which I
suspect are probably correct.
I think its utility and purpose are under appreciated. But it really needs
to be worked on some more to make a case for promoting it into more boost
usage.
Also this might be related to scaler
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

I think its utility and purpose are under appreciated. But it really needs to be worked on some more to make a case for promoting it into more boost usage. Not by us! I really promote this strong typedef in our team. I even think this should be in the c++ standard. Something like the normal typedef, but also something like the strong_typedef.
But perhaps you can have a look at the article: 'True typedefs' from Matthew Wilson (C++ Users Journal march 2003). Wkr, me

gast128 schrieb:
I think its utility and purpose are under appreciated. But it really needs to be worked on some more to make a case for promoting it into more boost usage.
Not by us! I really promote this strong typedef in our team. I even think this should be in the c++ standard.
http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2004/n1706.pdf -- Stefan Strasser

Not by us! I really promote this strong typedef in our team. I even think this should be in the c++ standard.
http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2004/n1706.pdf
Even better. One still cannot accuse me from having original ideas... Wkr, me

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
participants (3)
-
gast128
-
Robert Ramey
-
Stefan Strasser