boost::result_of and gcc
Hello, I'm running into a problem when using boost::result_of with gcc 3.4.2 and 4.2.1 (with MingW). The following program compiles fine with Visual C++ 8.0, but not with gcc: ------------------------------- #include <boost/utility/result_of.hpp> struct test_function1 { template <typename SignatureT> struct result; template <typename T> struct result<test_function1 (T)> { typedef T type; }; template <typename T> T operator () (T t) const { return t; } }; template <typename ArgT> struct test_function2 { template <typename SignatureT> struct result; template <typename T> struct result<test_function2 (T)> { typedef T type; }; template <typename T> T operator () (T t) const { return t; } }; int main(int argc, char *argv[]) { typedef boost::result_of< test_function1(int)>::type result_type; typedef boost::result_of< test_function2<float>(int)>::type result_type; return 0; } ------------------------------- The error message I get is for the second typedef using test_function2: E:/Projects/Third Party/boost/boost/utility/result_of.hpp: In instantiation of `boost::detail::result_of_nested_result<test_function2<float>, test_function2<float> ()(int)>': E:/Projects/Third Party/boost/boost/utility/result_of.hpp:75: instantiated from `boost::detail::result_of_impl<test_function2<float>, test_function2<float> ()(int), false>' E:/Projects/Third Party/boost/boost/utility/detail/result_of_iterate.hpp:24: instantiated from `boost::result_of<test_function2<float> ()(int)>' main.cpp:43: instantiated from here E:/Projects/Third Party/boost/boost/utility/result_of.hpp:68: error: invalid use of undefined type `struct test_function2<float>::result<test_function2<float> ()(int)>' I get the same error if I simply wrap test_function1 in another template class as nested struct and then use it instead of test_function2. Am I attempting to do something fundamentally wrong here, or is it a bug in gcc? Thanks, Martin
Martin Ecker wrote:
Hello,
I'm running into a problem when using boost::result_of with gcc 3.4.2 and 4.2.1 (with MingW).
The following program compiles fine with Visual C++ 8.0, but not with gcc:
<snip code>
I get the same error if I simply wrap test_function1 in another template class as nested struct and then use it instead of test_function2.
Am I attempting to do something fundamentally wrong here, or is it a bug in gcc?
It's a compiler bug fixed with GCC 4.2.2. But it's often a good idea to deduce the function object's type (especially in case operator() is const qualified): template< class Self, typename T > struct result< Self(T) > ... Regards, Tobias
participants (2)
-
Martin Ecker
-
Tobias Schwinger