|
Boost Users : |
Subject: [Boost-users] Template operator() overloading for types in a mpl::vector
From: Olivier Tournaire (olitour_at_[hidden])
Date: 2009-11-02 05:48:36
Hi all,
I am currently trying to write a simple functor, and I would like to have
the same overload for the operator () for all types in a mpl::vector.
// Types definitions
// Gray image types
typedef boost::mpl::vector< boost::gil::gray8_image_t ,
boost::gil::gray16_image_t , boost::gil::gray32_image_t,
boost::gil::gray32F_image_t , boost::gil::gray64F_image_t >
gray_image_types;
// RGB image types
typedef boost::mpl::vector< boost::gil::rgb8_image_t ,
boost::gil::rgb16_image_t , boost::gil::rgb32_image_t > rgb_image_types;
// Functor to compute min / max of an image over channels
struct pixel_compare_less
{
template <typename PixelType>
bool operator()( const PixelType& p1 , const PixelType& p2 ) const
{
return at_c<0>(p1) < at_c<0>(p2);
}
};
struct any_view_min_max
{
typedef std::pair<float, float> result_type;
template <typename View>
result_type operator()(const View& v) const
{
typedef typename View::iterator iterator;
std::pair< iterator, iterator > result = boost::minmax_element(
v.begin() , v.end() , pixel_compare_less() );
return std::make_pair( *(result.first) , *(result.second) );
}
};
This works fine for 'gray_image_types', but need to be specialized for types
in rgb_image_types. The specialization is the same, so, I am looking for an
automated way to do this. "Manually", I can write this:
template <>
any_view_min_max_optimized::result_type
any_view_min_max_optimized::operator()<rgba8_view_t>(const rgb8_view_t& v)
const
{
// ...
}
template <>
any_view_min_max_optimized::result_type
any_view_min_max_optimized::operator()<rgba16_view_t>(const rgb16_view_t& v)
const
{
// ...
}
And so on ... Could you help me to have an efficient way to do this for all
types 'rgb_image_types' without writing each specialization ?
Regards,
Olivier
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