Boost logo

Boost :

Subject: Re: [boost] [Boost-commit] svn:boost r77506 - in trunk: boost/property_map libs/property_map/doc libs/property_map/test
From: Michel Morin (mimomorin_at_[hidden])
Date: 2012-03-24 00:30:16


> Author: jewillco
> Date: 2012-03-23 15:35:52 EDT (Fri, 23 Mar 2012)
> New Revision: 77506
> URL: http://svn.boost.org/trac/boost/changeset/77506
[…]
> --- (empty file)
> +++ trunk/boost/property_map/function_property_map.hpp  2012-03-23
[…]
> +#ifndef BOOST_PROPERTY_MAP_FUNCTION_PROPERTY_MAP_H
> +#define BOOST_PROPERTY_MAP_FUNCTION_PROPERTY_MAP_H
[…]
> +#endif /* BOOST_PROPERTY_MAP_FUNCTION_PROPERTY_MAP_H */

s/H/HPP

> +template<typename Func, typename Key, typename Ret = typename boost::result_of<Func(Key)>::type>
> +class function_property_map: public put_get_helper<Ret, function_property_map<Func, Key, Ret> > {
[…]
> +  typedef Ret reference;
[…]
> +  reference operator[](const Key& k) const {
> +    return f(k);
> +  }
> +
> +  reference operator[](const Key& k) {
> +    return f(k);
> +  }
[…]
> +  private:
> +  Func f;
> +};

In const version of the subscript operator, `f` is treated as `const Func`.
So `reference` might not be appropriate for its return type.
You can avoid this issue by making `f` mutable.

Or, how about defining the default template argument of `Ret` as
`boost::result_of<const Func(Key)>::type` and removing non-const version of
the subscript operator? (Since property maps are often passed around by values,
it makes less sense to allow stateful functors in
`function_property_map`, IMHO.)

Regards,
Michel


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