1746: Have graph_image<P, V> work with V = bool as well.

https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Roland Levillain <roland@lrde.epita.fr> Have graph_image<P,V> work with V = bool as well. * mln/core/graph_image.hh (graph_image<P,V>::lvalue, 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... (graph_image<P,V>::operator()(const graph_psite<P>&)) (graph_image<P,V>::operator()(const graph_psite<P>&) const): ...these operators. graph_image.hh | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) Index: mln/core/graph_image.hh --- mln/core/graph_image.hh (revision 1745) +++ mln/core/graph_image.hh (working copy) @@ -104,10 +104,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; @@ -127,10 +132,10 @@ void init_(const p_graph<P>& g, const std::vector<V>& val); /// Read-only access of pixel value at point site \p p. - const V& operator()(const graph_psite<P>& p) const; + rvalue operator()(const graph_psite<P>& p) const; /// Read-write access of pixel value at point site \p p. - V& operator()(const graph_psite<P>& p); + lvalue operator()(const graph_psite<P>& p); /// Accessors. /// \{ @@ -234,7 +239,7 @@ template <typename P, typename V> inline - const V& + typename graph_image<P, V>::rvalue graph_image<P, V>::operator()(const graph_psite<P>& p) const { mln_precondition(&p.pg() == &this->data_->pg_); @@ -244,7 +249,7 @@ template <typename P, typename V> inline - V& + typename graph_image<P, V>::lvalue graph_image<P, V>::operator()(const graph_psite<P>& p) { mln_precondition(&p.pg() == &this->data_->pg_);
participants (1)
-
Roland Levillain