dimanche 1 mai 2016

c++ having trouble storing tuple of pointers

I have an object 'S' that stores a simple tuple of pointers, which is made flexible by the use of variadic templates. There are two methods, store() and store2(). The first one (store) works fine. The second one won't compile because std::make_tuple fails with the error:

'No matching function for call to 'make_tuple'

It further adds that there is no known conversation from 'B*' to 'B*&&' for 1st argument (this error is deep in the tuple library header).

Code is here:

#include <tuple>
#include <utility>

template<typename...Rs>
struct S
{
    void store(std::tuple<Rs*...> rs)
    {
        rs_ = rs;
    }

    void store2(Rs*...rs)
    {
        rs_ = std::make_tuple<Rs*...>(rs...); // This is the guy that breaks
    }

private:
    std::tuple<Rs*...> rs_;
};

struct B
{};

struct A : S<B, B>
{};


int main()
{
    auto *b1 = new B;
    auto *b2 = new B;
    auto *a1 = new A;


    a1->store(std::make_tuple(b1, b2));   // This works
    a1->store2(b1, b2);                   // How can I get this to work? (It causes an error in std::make_tuple of store2 above)
}

Aucun commentaire:

Enregistrer un commentaire