Search code examples
c++metaprogramminginvokesfinaeboost-fusion

Boost Fusion invoke and SFINAE


I would like to achieve partial class template specialization based on whether boost::fusion::invoke() with a particular Fusion sequence would work or not. But it seems that substitution failure in this case IS an error.

I guess I need an is_callable_with_these_sequence_parameters<F, Seq> metafunction that works. Can anyone help?

struct F
{
    template<class> struct result;
    template<class F> struct result<F(float)> { typedef int type; };
    int operator()(float) { std::cout << "invoked (float)\n"; }
};

template <class Sequence, class Enable=void>
struct A
{
    A() { std::cout << "invoked nothing\n"; }
};

// Partial specialization
template <class Sequence>
struct A<Sequence, typename boost::fusion::result_of::invoke<F, Sequence>::type>
{
    A() { boost::fusion::invoke(F(), Sequence()); }
};

static void test()
{
    A<boost::fusion::vector<float> >(); // should print "invoked (float)"
    A<boost::fusion::vector<char, char> >(); // should print "invoked nothing"
}

Solution

  • After some investigation I think that this is a bug in boost.

    Reported here, no workarounds so far.


    Update: some incorrect behavior of boost::fusion has been fixed, according to the ticket.