c++ - const-correctness of data-accessor types - better solution? -
i'm working on image-class makes possible work images different pixel layouts (rgb, rgba, gray, bayer, ...). access pixel it's possible call image.at<pixeltype>(x,y) returns "accessor". concrete accessor-implementation dependent on template argument. i've ran issues regarding const correctness. here dumbed down implementation makes apparent: template<bool constaccessor> class accessor { public: typedef typename boost::mpl::if_c<constaccessor, const int, int>::type datatype; accessor(datatype& data) :data(data) { } accessor(accessor<false>& other) : data(other.data) { } datatype& data; }; class image { public: accessor<false> at(unsigned int x, unsigned int y) { return accessor<false>(data); } accessor<true> at(unsigned int x, unsigned int y) const { return accessor<true>(data); } private: int data; }; int main() { im...