Boost logo

Boost Users :

Subject: Re: [Boost-users] [GIL] bits8* to gray8_ptr_t without reinterpret_cast?
From: Christian Henning (chhenning_at_[hidden])
Date: 2011-05-25 11:14:57


Hi Tyler,

> template<class Dest, class Src>
> Dest gil_safe_ptr_cast(Src src)
> {
>     // this cast is unsafe, use reinterpret_cast
>     BOOST_STATIC_ASSERT(false);
> }
> template<> boost::gil::gray8_ptr_t gil_safe_ptr_cast(boost::gil::bits8*
> pBits8)
> {
>     return reinterpret_cast<boost::gil::gray8_ptr_t>(pBits8);
> }
> boost::gil::bits8* pBits8 = data8;
> boost::gil::gray8_ptr_t pGray8 =
> gil_safe_ptr_cast<boost::gil::gray8_ptr_t>(pBits8); // works
> boost::gil::bits16* pBits16 = NULL;
> boost::gil::gray8_ptr_t pGray82 =
> gil_safe_ptr_cast<boost::gil::gray8_ptr_t>(pBits16); // compile error as
> expected
>
> If this is the best current solution, I'd be glad to clean it up and pack it
> into typedefs.hpp for grayscale types. Thoughts?

I think this is a good solution to have the compiler assert when a
cast is unsafe. I don't have a better idea right now.

Regards,
Christian


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