GIL: how to convert an any_image_view to its const equivalent?

Dear list, I think GIL is not able to convert an any_image_view to its const equivalent or I don't know how to do it. The variant class checks in its constructor if it can hold the given type but it doesn't have a constructor to convert an any_image_view from one to another. Here is a simple piece of code declaring two any_image_views: typedef boost::gil::any_image_view< boost::mpl::vector< boost::gil::rgba8_view_t >
image_view;
typedef boost::gil::any_image_view< boost::mpl::vector< boost::gil::rgba8c_view_t >
const_image_view;
Now when I try to construct a const_image_view from an image_view I get an std::bad_cast exception. What can I do about it? Cheers, Philipp -- View this message in context: http://www.nabble.com/GIL%3A-how-to-convert-an-any_image_view-to-its-const-e... Sent from the Boost - Dev mailing list archive at Nabble.com.

Philipp Reh wrote:
I think GIL is not able to convert an any_image_view to its const equivalent or I don't know how to do it.
Philipp, Thanks for discovering this problem. Here is a workaround for you (tested on Visual Studio 2005 only): using namespace boost::gil; namespace detail { template <typename Dst> struct variant_const_assign_fn { typedef void result_type; Dst& _dst; variant_const_assign_fn(Dst& dst) : _dst(dst) {} template <typename Src> void operator()(const Src& src) const { typename Src::const_t const_src(src); _dst = const_src; } }; } template <typename V1, typename V2> void variant_const_assign(const variant<V1>& src, variant<V2>& dst) { ::detail::variant_const_assign_fn<variant<V2> > fn(dst); apply_operation(src,fn); } int main() { typedef boost::mpl::vector<rgb8_view_t, gray16_view_t> my_views_t; any_image_view<my_views_t> my_any_view; any_image_view<my_views_t>::const_t my_const_any_view; variant_const_assign(my_any_view, my_const_any_view); // This will throw an exception - cannot assign to const destination variant_const_assign(my_const_any_view, my_any_view); } Lubomir

Lubomir Bourdev wrote:
Thanks for discovering this problem.
Here is a workaround for you (tested on Visual Studio 2005 only):
Hi, Lubomir. Sorry for replying so late. The workaround works fine with gcc-4.3.1 as well. Cheers, Philipp -- View this message in context: http://www.nabble.com/GIL%3A-how-to-convert-an-any_image_view-to-its-const-e... Sent from the Boost - Dev mailing list archive at Nabble.com.
participants (2)
-
Lubomir Bourdev
-
Philipp Reh