Pavol Droba <[EMAIL PROTECTED]> writes:

> Hi,
>
> I have developed a simple cast function which I found very useful. Here it is:
>
>       template< typename T >
>       inline T offset_cast( void* p, unsigned int  offset=0 )
>       {
>               return reinterpret_cast< T >( static_cast<unsigned char*>( p )+offset 
>); 
>       }
>       
>       template< typename T >
>       inline T offset_cast( const void* p, unsigned int offset=0 )
>       {
>               return reinterpret_cast< T >( static_cast<const unsigned char*>( p 
>)+offset ); 
>       }
>
> Its purposes is to simplify a mapping of C-like structure onto binary data. Here is 
> the example: Assume thath you have a network packet in raw format, and you want
> to read IP-header information. You could do following:
>
>       ip_header* ip=offset_cast<ip_header>( packet, ip_header_offset );
>
> instead of ugly pointer arithmetic.
>
> Is there any interest for something like this in Boost?

My answer: "not if it uses reinterpret_cast, since that's not
portable".

-- 
                       David Abrahams
   [EMAIL PROTECTED] * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to