[result_of] const-qualified function?

Hi, gurus. I have one question about 'result_of': template<class F> struct forward { template<class A> // typename boost::result_of<F(A&)>::type // (1) typename boost::result_of<F const(A&)>::type // (2) operator()(A& a) const { return m_f(a); } explicit forward(F f) : m_f(f) { } private: F m_f; }; (1) or (2).. which is right? In fact, (2) fails to compile if 'F' is a function pointer type; because const function-pointer specialization is missing. Regards, -- Shunsuke Sogame

shunsuke wrote:
Hi, gurus.
I have one question about 'result_of':
template<class F> struct forward { template<class A> // typename boost::result_of<F(A&)>::type // (1) typename boost::result_of<F const(A&)>::type // (2) operator()(A& a) const { return m_f(a); }
explicit forward(F f) : m_f(f) { }
private: F m_f; };
(1) or (2).. which is right?
(2) is right because m_f is const in operator().
In fact, (2) fails to compile if 'F' is a function pointer type; because const function-pointer specialization is missing.
This is a bug in boost::result_of.

Peter Dimov wrote:
shunsuke wrote:
Hi, gurus.
I have one question about 'result_of':
template<class F> struct forward { template<class A> // typename boost::result_of<F(A&)>::type // (1) typename boost::result_of<F const(A&)>::type // (2) operator()(A& a) const { return m_f(a); }
explicit forward(F f) : m_f(f) { }
private: F m_f; };
(1) or (2).. which is right?
(2) is right because m_f is const in operator().
In fact, (2) fails to compile if 'F' is a function pointer type; because const function-pointer specialization is missing.
This is a bug in boost::result_of.
Hmm, the result_of revolution is painful... Thanks! -- Shunsuke Sogame

shunsuke wrote:
Peter Dimov wrote:
shunsuke wrote:
Hi, gurus.
I have one question about 'result_of':
template<class F> struct forward { template<class A> // typename boost::result_of<F(A&)>::type // (1) typename boost::result_of<F const(A&)>::type // (2) operator()(A& a) const { return m_f(a); }
explicit forward(F f) : m_f(f) { }
private: F m_f; };
(1) or (2).. which is right? (2) is right because m_f is const in operator().
...unless F is a reference.
In fact, (2) fails to compile if 'F' is a function pointer type; because const function-pointer specialization is missing. This is a bug in boost::result_of.
Hmm, the result_of revolution is painful...
FunctionTypes provides a reimplementation of result_of (as one of its examples) that can handle top-level cv-qualification correctly. http://tinyurl.com/qaf5f - zip archive I replaced my local copy with it as boost::result_of was completely broken, recently (renaming "namespace example" to "namespace boost") and didn't experience any problems. We can eventually replace boost::result_of with it, once FT is in and testing is back for the HEAD revision... (BTW: the GCC configuration of FT has been fixed, so the problems reported during the review should be gone.) Regards, Tobias

On Jan 27, 2007, at 12:27 PM, Tobias Schwinger wrote:
In fact, (2) fails to compile if 'F' is a function pointer type; because const function-pointer specialization is missing. This is a bug in boost::result_of.
Hmm, the result_of revolution is painful...
FunctionTypes provides a reimplementation of result_of (as one of its examples) that can handle top-level cv-qualification correctly.
http://tinyurl.com/qaf5f - zip archive
I replaced my local copy with it as boost::result_of was completely broken, recently (renaming "namespace example" to "namespace boost") and didn't experience any problems.
Good to know. Yes, boost::result_of is a mess. It was half-baked when I originally implemented it, and I haven't had a chance to go back and fix it.
We can eventually replace boost::result_of with it, once FT is in and testing is back for the HEAD revision...
I'm looking forward to this! Cheers, Doug
participants (4)
-
Doug Gregor
-
Peter Dimov
-
shunsuke
-
Tobias Schwinger