typesafe typedef that is not implicitly convertible
I am unable to find it now, but I thought I saw that there is a boost way to define a typedef using a unique class that cannot be implicitly converted to another type. Thus, typedef int Foo; void bar( Foo a ); would compile only with bar( Foo(3) ) not bar(3) Is this capability in Boost 1.33 or am I hallucinating? Thanks, Phil
On 1/23/07, pwm
I am unable to find it now, but I thought I saw that there is a boost way to define a typedef using a unique class that cannot be implicitly converted to another type. Thus,
typedef int Foo; void bar( Foo a );
would compile only with bar( Foo(3) ) not bar(3)
Is this capability in Boost 1.33 or am I hallucinating?
Thanks, Phil
strong_typedef.hpp? (http://www.boost.org/boost/strong_typedef.hpp) Tony
Gottlob Frege wrote:
strong_typedef.hpp? ( http://www.boost.org/boost/strong_typedef.hpp)
Yes, that is EXACTLY what I was looking for. It seems buried inside the Serialization library, and I could find no documentation for it. Thanks for the help! Phil
Documentation for it is inside the serialization library under misc. Robert Ramey pwm wrote:
Gottlob Frege wrote:
strong_typedef.hpp? ( http://www.boost.org/boost/strong_typedef.hpp)
Yes, that is EXACTLY what I was looking for. It seems buried inside the Serialization library, and I could find no documentation for it.
Thanks for the help!
Phil
There is BOOST_STRONG_TYPEDEF which is part of the serialization library. I made it so that "typedefs" could be used as template parameters and still be distinguishable between each other. I did leave the implict convertability in there though so maybe its not what you need. BOOST_STRONG_TYPEDEF Foo int; void bar(Foo a); // ok { Foo a; bar(a);// ok int b bar(b);// compile error b += a;// ok - implicit conversion like int ... } Robert Ramey
participants (3)
-
Gottlob Frege
-
pwm
-
Robert Ramey