Boost logo

Boost :

From: Lubomir Bourdev (lbourdev_at_[hidden])
Date: 2008-08-14 16:20:48


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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk