
Hi all, It is know that typedef in C++ is actually an alias, i.e. it doesn't create new distinguishable type. Sometimes this causes problems. Consider following example: typedef int handle; template < typename Value > void write( const Value &value ); void write< int >( const int &value ) { // do processing for int } void write< handle >( const handle &value ) { // we wanted to have separate processing for handle, // but we get only compilation error :( } In my projects I resolve such situations as the following: class handle_tag { }; typedef tagged< int, handle_tag > handle; Then everything works as expected. "tagged" class is actually a wrapper that mimics fundamental type behaviour. Also I have specialization for pointers. Is anyone interested in such solution of given problem? Is it worth to be part of Boost? Sincerely, Maksym Motornyy.

On 6/1/05, Maksym Motornyy <mmotorny@yandex.ru> wrote:
Then everything works as expected. "tagged" class is actually a wrapper that mimics fundamental type behaviour. Also I have specialization for pointers.
Is anyone interested in such solution of given problem? Is it worth to be part of Boost?
See perhaps <boost/strong_typedef.hpp> -- Caleb Epstein caleb dot epstein at gmail dot com

See perhaps <boost/strong_typedef.hpp>
Unfortunately BOOST_STRONG_TYPEDEF doesn't work as expected. For example: BOOST_STRONG_TYPEDEF( int, handle ); template< typename Value > void write( const Value &value ) { } template<> void write< int >( const int &value ) { cout << "int: " << value << endl; } template<> void write< handle >( const handle &value ) { cout << "handle: " << value << endl; } int main( int, char ** ) { handle h( 8 ); write( --h ); return 0; } This code will print "int: 7" (but I'm expecting "handle: 7"). I have an implementation that deals with such cases. Sincerely, Maksym.

Maksym Motornyy wrote:
See perhaps <boost/strong_typedef.hpp>
I didn't know about BOOST_STRONG_TYPEDEF's existence until Caleb mentioned it. When I looked for documentation, I found it was part of the Serialization library. Perhaps the documentation belongs to another section (this also goes for static_warning, smart_cast, etc.). (I didn't check the CVS, I checked the 1.32 release; sorry if it's already fixed) Boost contains many useful things under the hood ;). Apropos, some classes I use are from boost/detail (e.g., atomic_count). I feel guilty having to write "detail" when using them... will they become part of public boost some day?
This code will print "int: 7" (but I'm expecting "handle: 7"). I have an implementation that deals with such cases.
You mean something like Matthew Wilson's (www.stlsoft.com) true_typedef?
participants (3)
-
Ariel Badichi
-
Caleb Epstein
-
Maksym Motornyy