promote "unwrap" to ref.hpp
Hi all, boost::reference_wrapper exists at the top-level of boost (in boost/ ref.hpp), but that header provides no way to unwrap a reference_wrapper. There are two implementations floating around of "unwrap", one in boost.bind's implementation details, and one in boost.mpl's implementation details. Is there any problem with providing a version of unwrap in ref.hpp? ron
Ronald Garcia:
Hi all,
boost::reference_wrapper exists at the top-level of boost (in boost/ ref.hpp), but that header provides no way to unwrap a reference_wrapper. There are two implementations floating around of "unwrap", one in boost.bind's implementation details, and one in boost.mpl's implementation details. Is there any problem with providing a version of unwrap in ref.hpp?
What is the specification of unwrap that you have in mind?
On May 16, 2008, at 6:33 PM, Peter Dimov wrote:
Ronald Garcia:
Hi all,
boost::reference_wrapper exists at the top-level of boost (in boost/ ref.hpp), but that header provides no way to unwrap a reference_wrapper. There are two implementations floating around of "unwrap", one in boost.bind's implementation details, and one in boost.mpl's implementation details. Is there any problem with providing a version of unwrap in ref.hpp?
What is the specification of unwrap that you have in mind?
Something like the following: template< typename F > inline F& unwrap(F& f) { return f; } template< typename F > inline F& unwrap(reference_wrapper<F>& f) { return f; } template< typename F > inline F& unwrap(reference_wrapper<F> const& f) { return f; } The above is adapted from the mpl implementation. ron
On Sat, May 17, 2008 at 4:01 AM, Ronald Garcia <garcia@cs.indiana.edu> wrote:
On May 16, 2008, at 6:33 PM, Peter Dimov wrote:
Ronald Garcia:
Hi all,
boost::reference_wrapper exists at the top-level of boost (in boost/ ref.hpp), but that header provides no way to unwrap a reference_wrapper. There are two implementations floating around of "unwrap", one in boost.bind's implementation details, and one in boost.mpl's implementation details. Is there any problem with providing a version of unwrap in ref.hpp?
What is the specification of unwrap that you have in mind?
Something like the following:
template< typename F > inline F& unwrap(F& f) { return f; }
template< typename F > inline F& unwrap(reference_wrapper<F>& f) { return f; }
template< typename F > inline F& unwrap(reference_wrapper<F> const& f) { return f; }
What about the corresponding metafunctions that compute the result value? -- gpd
Those are already provided by ref.hpp. That's part of why I think it makes sense to provide the function corresponding to the metafunctions. ron On May 17, 2008, at 3:12 PM, Giovanni Piero Deretta wrote:
What about the corresponding metafunctions that compute the result value?
On Friday 16 May 2008 22:01, Ronald Garcia wrote:
Something like the following:
template< typename F > inline F& unwrap(F& f) { return f; }
template< typename F > inline F& unwrap(reference_wrapper<F>& f) { return f; }
template< typename F > inline F& unwrap(reference_wrapper<F> const& f) { return f; }
Couldn't you do a little better (half the number of overloads) by using boost::unwrap_reference for the return type? For example, template<typename F> boost::unwrap_reference<F>::type& unwrap(F &f) { return f; } -- Frank
That looks good to me! Thanks for that. ron On May 18, 2008, at 12:28 AM, Frank Mori Hess wrote:
Couldn't you do a little better (half the number of overloads) by using boost::unwrap_reference for the return type? For example,
template<typename F> boost::unwrap_reference<F>::type& unwrap(F &f) { return f; }
Since I haven't heard any more conversation about this, would it be alright to add Frank's implementation below to ref.hpp? Is anything more needed? ron On May 17, 2008, at 9:28 PM, Frank Mori Hess wrote:
On Friday 16 May 2008 22:01, Ronald Garcia wrote:
Something like the following:
template< typename F > inline F& unwrap(F& f) { return f; }
template< typename F > inline F& unwrap(reference_wrapper<F>& f) { return f; }
template< typename F > inline F& unwrap(reference_wrapper<F> const& f) { return f; }
Couldn't you do a little better (half the number of overloads) by using boost::unwrap_reference for the return type? For example,
template<typename F> boost::unwrap_reference<F>::type& unwrap(F &f) { return f; }
-- Frank
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/ listinfo.cgi/boost
participants (4)
-
Frank Mori Hess -
Giovanni Piero Deretta -
Peter Dimov -
Ronald Garcia