compute icon indicating copy to clipboard operation
compute copied to clipboard

Binding custom function fails to compile if function has more than three arguments

Open rgreenblatt opened this issue 5 years ago • 3 comments

For instance adding the following to test/test_functional_bind.cpp causes a compiler error:

BOOST_AUTO_TEST_CASE(bind_more_than_four)
{
    int data[] = { 1, 2, 3, 4 };
    compute::vector<int> vector(data, data + 4, queue);

    BOOST_COMPUTE_FUNCTION(int, add_four_nums, 
                           (int first, int second, int third, int fourth),
    {
        return first + second + third + fourth;
    });

    compute::transform(
        vector.begin(), vector.end(), vector.begin(),
        compute::bind(add_four_nums, _1, 2, 3, 4),
        queue
    );
}

The full error and build log can be found here: https://pastebin.com/MnHi2WZs. I am using ubuntu 18.04 with libboost1.65-dev and g++ 7.4. This reproduces for a variety of different argument types etc.

As far as I know, the best work around is to adapt a struct which contains to arguments.

rgreenblatt avatar Jun 11 '19 22:06 rgreenblatt

This occurs because in this section, the number of arguments only go up to three. I will make a pr to address this.

rgreenblatt avatar Jun 13 '19 19:06 rgreenblatt

Can you try enabling C++11 for Boost.Compute by defining BOOST_COMPUTE_USE_CPP11? This should enable the variadic template version from line 221. If you need C++03 version you can create PR to add versions with more arguments, or do in your code.

jszuppe avatar Jun 13 '19 20:06 jszuppe

I was incorrect about the code causing this issue. The actual issue is in this section: https://github.com/boostorg/compute/blob/master/include/boost/compute/functional/bind.hpp#L145. The issue isn't resolved by enabling c++11 because there is no variadic template version of apply_invoked_bound_function. I don't know how to use variadic templates to generalize apply_invoked_bound_function, but I would be happy to make a pr to add additional versions of the function up to some larger number of arguments.

rgreenblatt avatar Jun 14 '19 13:06 rgreenblatt