
Hi Tyler,
template
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_castboost::gil::gray8_ptr_t(pBits8); } boost::gil::bits8* pBits8 = data8; boost::gil::gray8_ptr_t pGray8 = gil_safe_ptr_castboost::gil::gray8_ptr_t(pBits8); // works boost::gil::bits16* pBits16 = NULL; boost::gil::gray8_ptr_t pGray82 = gil_safe_ptr_castboost::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