2
votes

Trying to compile the following call to boost::fusion::invoke in boost-1.56 fails in Visual Studio 2013 but there is no error when compiling with Visual Studio 2012.

#include <boost/bind.hpp>
#include <boost/function.hpp>

#include <boost/fusion/functional.hpp>

void Function( int & output )
{
  output = 12;
}

int main( int, char ** )
{
  boost::fusion::vector1< int > parameters;
  boost::function< void( int & ) > function = &Function;

  boost::fusion::invoke( function, parameters );

  return 0;
}

The compiler output is:

boost\fusion\functional\invocation\invoke.hpp(205): error C2039: 'type' : is not a member of 'boost::result_of<Function (const int &)>'
    with
    [
        Function=boost::function<void (int &)>
    ]
    boost\fusion\functional\invocation\invoke.hpp(163) : see reference to class template instantiation 'boost::fusion::detail::invoke_impl<boost::function<void (int &)>,Sequence,1,false,true>' being compiled
    with
    [
        Sequence=const boost::fusion::vector1<int>
    ]
    main.cpp(16) : see reference to class template instantiation 'boost::fusion::result_of::invoke<boost::function<void (int &)>,const boost::fusion::vector1<int>>' being compiled

It's failing when trying to instantiate boost::result_of with a const Sequence. I've looked in boost\fusion\functional\invocation\invoke.hpp and there are two overloads of boost::fusion::invoke, one is const and the other is non-const.

I think that the Visual Studio 2013 compiler is attempting to instantiate the const version even though that is not the one that should be called. If I comment out the const version in invoke.hpp the example compiles fine.

Is this a bug with Visual Studio 2013 or boost-1.56?

Is there any workaround for this problem without modifying the boost sources?

1
In Visual studio 2012 and boost 1.55 it compiles fine. - Yochai Timmer
I'm sorry I don't know enough about the problem to give an authoritative answer (I'd say the bug was in VS2012), but I have checked your program on Coliru and found that both g++ and clang++ also give errors when using c++11. In case they help, the following (slightly modified) approaches work with g++/clang++ c++11/no-c++11: Output argument and Input argument. - llonesmiz
@cv_and_he Thanks. Your output argument solution works but unfortunately this was just a stripped down example of the problem. In the real world version we can't have a fusion vector with references as there are no values to initialise them with. - fun4jimmy

1 Answers

5
votes

I suspect the default for BOOST_RESULT_OF has changed for VS2013.

#define BOOST_RESULT_OF_USE_TR1

makes it compile. Chances are this bug is known and has been fixed in trunk, but you might want to report it still