2

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"
}
paperjam
  • 8,321
  • 12
  • 53
  • 79
  • Uhh. I think I understood the code, but can't see what's wrong with it. What *should* it print? Could you clarify? – ulidtko May 17 '12 at 09:29
  • It does not compile as-is on MSVC 2010. Partial specialization does not seem to work as I had hoped. – paperjam May 17 '12 at 09:31

1 Answers1

3

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.

ulidtko
  • 14,740
  • 10
  • 56
  • 88