What result_type ? And why?

I wrote the following functor: struct ASCII_lower { template< typename CharT > CharT operator() (const CharT& ch) const { if (ch >= 'A' && ch <= 'Z') return ch+0x20; return ch; // unchanged } }; and when I used it to create a transformed_range, I get an error that it doesn't find result_type in ASCII_lower. Since the return type depends on the argument, how could I declare a result_type? And why do I need it? Lambda functions don't have it, and I thought it was fairly old fashioned and optional for helping figure out the result type if necessary.

On 19/07/2011 3:16, John M. Dlugosz wrote:
Since the return type depends on the argument, how could I declare a result_type?
You can see how to do it here http://www.boost.org/doc/libs/1_47_0/libs/utility/utility.htm#result_of Agustín K-ballo Bergé.- http://talesofcpp.blogspot.com

I wrote the following functor:
struct ASCII_lower { template< typename CharT > CharT operator() (const CharT& ch) const { if (ch >= 'A' && ch <= 'Z') return ch+0x20; return ch; // unchanged } };
and when I used it to create a transformed_range, I get an error that it doesn't find result_type in ASCII_lower. Since the return type depends on the argument, how could I declare a result_type?
And why do I need it? Lambda functions don't have it, and I thought it was fairly old fashioned and optional for helping figure out the result type if necessary.
In C++0x, it is not necessary to help the compiler figure out the return type of a functor in any way - it can do it using decltype. To enable this functionality in boost, you need to define the symbol BOOST_RESULT_OF_USE_DECLTYPE Regards, Nate.
participants (3)
-
Agustín K-ballo Bergé
-
John M. Dlugosz
-
Nathan Ridge