Boost logo

Boost Users :

Subject: [Boost-users] Compiler craziness on boost::result_of ? Please help
From: John M. Dlugosz (mpbecey7gu_at_[hidden])
Date: 2012-04-13 11:02:07


I'm using Visual Studio 10, and Boost 1.49. The following complete CPP file compiles
without error:

=====
#include <boost/test/unit_test.hpp>
#include "boost/thread/future.hpp"
#include <boost/utility/result_of.hpp>
#include <functional>

using boost::unique_future;

template <typename F>
unique_future<typename boost::result_of< F() >::type>
foo (F&& f)
  {
  typedef typename boost::result_of< F() >::type RetType;
  unique_future<RetType> future_result;
  return std::move(future_result);
  }

template <typename F, typename A1>
unique_future<typename boost::result_of< F(A1) >::type>
foo (F&& f, A1&& a1)
  {
  return std::move(foo (std::tr1::bind(f,a1)));
  }

class C {};

class D : public C {
public:
    void mf() const { }
// virtual void toxic() { }
    };

void mainfunc()
{

     D* p;
     foo (&D::mf, p);

}

=====

But, if you un-comment the definition of toxic, then it will not compile, giving instead:

1>E:\boost_1_49\boost/utility/result_of.hpp(82): error C2825: 'F': must be a class or
namespace when followed by '::'
1> E:\boost_1_49\boost/utility/result_of.hpp(90) : see reference to class
template instantiation 'boost::detail::result_of_nested_result<F,FArgs>' being compiled
1> with
1> [
1> F=void (__thiscall D::* &)(void) const,
1> FArgs=void (__thiscall D::* &(D *&))(void) const
1> ]
1> E:\boost_1_49\boost/utility/detail/result_of_iterate.hpp(33) : see reference
to class template instantiation 'boost::detail::tr1_result_of_impl<F,FArgs,HasResultType>'
being compiled
1> with
1> [
1> F=void (__thiscall D::* &)(void) const,
1> FArgs=void (__thiscall D::* &(D *&))(void) const,
1> HasResultType=false
1> ]
1> E:\boost_1_49\boost/utility/detail/result_of_iterate.hpp(75) : see reference
to class template instantiation 'boost::tr1_result_of<F>' being compiled
1> with
1> [
1> F=void (__thiscall D::* &(D *&))(void) const
1> ]
1> threadpoolTest.cpp(39) : see reference to class template instantiation
'boost::result_of<F>' being compiled
1> with
1> [
1> F=void (__thiscall D::* &(D *&))(void) const
1> ]
1>E:\boost_1_49\boost/utility/result_of.hpp(82): error C2516: 'F' : is not a legal base class
1> E:\boost_1_49\boost/utility/result_of.hpp(90) : see declaration of 'F'
1>E:\boost_1_49\boost/utility/result_of.hpp(82): error C2143: syntax error : missing ','
before '::'
1>E:\boost_1_49\boost/utility/result_of.hpp(82): error C2903: 'result' : symbol is neither
a class template nor a function template
1>E:\boost_1_49\boost/utility/result_of.hpp(82): error C2039: 'result' : is not a member
of '`global namespace''
1>E:\boost_1_49\boost/utility/result_of.hpp(82): error C2504: 'result' : base class undefined
1>E:\boost_1_49\boost/utility/result_of.hpp(82): error C2143: syntax error : missing ','
before '<'
1>threadpoolTest.cpp(39): error C2893: Failed to specialize function template
'boost::unique_future<boost::result_of<F(T0)>::type> foo(F &&,A1 &&)'
1> With the following template arguments:
1> 'void (__thiscall D::* &)(void) const'
1> 'D *&'
1>threadpoolTest.cpp(39): error C2780:
'boost::unique_future<boost::result_of<F(void)>::type> foo(F &&)' : expects 1 arguments -
2 provided
1> threadpoolTest.cpp(10) : see declaration of 'foo'
1>
1>Build FAILED.

Note that both the presence of a virtual function and a base class in necessary. if toxic
is present but C is not, then it still works.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net