Re: [boost] [Boost-commit] svn:boost r77506 - in trunk: boost/property_map libs/property_map/doc libs/property_map/test

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

On Sat, 24 Mar 2012, Michel Morin wrote:
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
I've fixed that.
+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.)
I did the second approach you mentioned. Please check r77514 and see if you like how I've incorporated your suggestions. Thank you for your comments. -- Jeremiah Willcock

Jeremiah Willcock wrote:
Please check r77514 and see if you like how I've incorporated your suggestions. Thank you for your comments.
Definitely, I like it ;) Thanks for your work, Jeremiah. Regards, Michel
participants (2)
-
Jeremiah Willcock
-
Michel Morin