0

im having some problem involving the move semantics asssociated with creating an std::tuple from a variadic template class. This is my class (it's using Qt but that's irrelevant):

template<typename ...Ts>
class QuestionBox : public QGroupBox
{

public:
    QuestionBox(const QString& question, Ts... args)
    {
        this->setTitle(question);
        layout = new QGridLayout(this);
        questionBoxElements = std::make_tuple<Ts...>(args...); //ERROR: Cannot bind rvalue ref QLabel*&& to lvalue QLabel* 

        auto loop = [&](auto& arg)
        {
            layout->addWidget(arg);
        };

        (loop(args), ...);
    }

private:
    QGridLayout* layout;
    std::tuple<Ts...> questionBoxElements;
};

and it is called as so:

auto divisionSlider = new FancySlider(0, 30);
auto divisionLabel1 = new QLabel("Ranking Duration (days) : ");
auto divisionLabel2 = new QLabel("Submission Duration (days) : ");

auto competitionDivison = new QuestionBox<FancySlider*, QLabel*, QLabel*>("How will the competition be divide up?", divisionSlider, divisionLabel1, divisionLabel2);

So, everything here is working fine, except the line marked as throwing an error. All I want to be done here is create a tuple of the provided types, and provided arguments.

I've tried replacing the line causing the error with:

questionBoxElements = std::make_tuple<Ts...>(std::move(args...)); 

and this causes the previous errors to go away, however, then I get a new error (for some not all types):

No matching function for call to 'move(Type1*&, Type2*&)'

I'm assuming that it's because the types which throw this error do not have a move constructor implemented? Is that correct?

jf192210
  • 127
  • 7
  • 4
    You're not supposed to provide template arguments for `make_tuple`. Let the compiler guess them and it should work. – HolyBlackCat Sep 13 '20 at 20:14
  • Since this has nothing to do with qt, you should remove all that stuff, and make a [mre] – cigien Sep 13 '20 at 20:14
  • @HolyBlackCat Oh hey, you're right, thanks for the swift response – jf192210 Sep 13 '20 at 20:18
  • @Holy Mind to write an answer? I couldn't find an appropriate dupe. – πάντα ῥεῖ Sep 13 '20 at 20:33
  • @πάνταῥεῖ I'm tempted to close as a dupe of some question explaining forwarding references. – HolyBlackCat Sep 13 '20 at 20:45
  • @Holy I found several there. But as mentioned not really appropriate ([this](https://www.google.com/search?q=site%3Astackoverflow.com+%22c%2B%2B%22+variadic+parameters+to+tuple&rlz=1C1CHBF_deDE833DE833&oq=s&aqs=chrome.1.69i60j69i59l3j69i60l4.9866j0j7&sourceid=chrome&ie=UTF-8) was my google query) – πάντα ῥεῖ Sep 13 '20 at 20:47
  • @πάνταῥεῖ Perhaps this https://stackoverflow.com/questions/34180636/what-is-the-reason-for-stdmake-tuple – cigien Sep 14 '20 at 00:11

0 Answers0