1744: Have line_graph_image<P, V> work with V = bool.

https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Roland Levillain <roland@lrde.epita.fr> Have line_graph_image<P,V> work with V = bool. * mln/core/line_graph_image.hh (line_graph_image<P,V>::lvalue, line_graph_image<P,V>::rvalue): Redefine using std::vector's associated types `reference' and `const_reference', so as to be able to form references on the elements of the image when its value type is `bool'. Use these associated types as return types for... (line_graph_image<P,V>::operator()(const line_graph_psite<P>&)) (line_graph_image<P,V>::operator()(const line_graph_psite<P>&) const): ...these operators. * mln/morpho/level_components.hh (morpho::level_components): Remove the kludge: actually use an image of `bool' instead of an image of `int' to tick the processed points. core/line_graph_image.hh | 17 +++++++++++------ morpho/level_components.hh | 12 +----------- 2 files changed, 12 insertions(+), 17 deletions(-) Index: mln/core/line_graph_image.hh --- mln/core/line_graph_image.hh (revision 1743) +++ mln/core/line_graph_image.hh (working copy) @@ -122,10 +122,15 @@ typedef V value; /// Return type of read-write access. - typedef V& lvalue; + /// + /// We use the associated type \c reference instead of a plain + /// reference on th value type (\v V), because it's the only way + /// to safely form a reference on the element in the case of a + /// std::vector<bool>. + typedef typename std::vector<V>::reference lvalue; /// Return type of read-only access. - typedef const V& rvalue; + typedef typename std::vector<V>::const_reference rvalue; /// Value set associated type. typedef mln::value::set<value> vset; @@ -149,10 +154,10 @@ const std::vector<V>& edge_val); /// Read-only access of pixel value at point site \p p. - const V& operator()(const line_graph_psite<P>& p) const; + rvalue operator()(const line_graph_psite<P>& p) const; /// Read-write access of pixel value at point site \p p. - V& operator()(const line_graph_psite<P>& p); + lvalue operator()(const line_graph_psite<P>& p); /// Accessors. /// \{ @@ -271,7 +276,7 @@ template <typename P, typename V> inline - const V& + typename line_graph_image<P, V>::rvalue line_graph_image<P, V>::operator()(const line_graph_psite<P>& p) const { mln_precondition(&p.plg() == &this->data_->plg_); @@ -281,7 +286,7 @@ template <typename P, typename V> inline - V& + typename line_graph_image<P, V>::lvalue line_graph_image<P, V>::operator()(const line_graph_psite<P>& p) { mln_precondition(&p.plg() == &this->data_->plg_); Index: mln/morpho/level_components.hh --- mln/morpho/level_components.hh (revision 1743) +++ mln/morpho/level_components.hh (working copy) @@ -99,17 +99,7 @@ const W& win = exact(win_); mln_ch_value(I, DestValue) labels(input.domain()); - /* FIXME: Yet another KLUDGE, this time required by the - specialization std::vector<bool>, which prevents forming - (mutable) reference to any of its elements. This creates - errors later with images using std::vector<bool> to store - their data (e.g., line_graph_image<P, V>). - - Alas, we cannot prevent the compiler to use this - specialization. Our workaround is simply... to use integers - instead of booleans. */ -// mln_ch_value(I, bool) processed(input.domain()); - mln_ch_value(I, int) processed(input.domain()); + mln_ch_value(I, bool) processed(input.domain()); level::fill (processed, false); DestValue cur_label = mln_min(DestValue);
participants (1)
-
Roland Levillain