c++ - 从可变模板参数创建一个 std::tuple
问题描述
std::tuple
我遇到了一些问题,涉及与从可变参数模板类创建关联的移动语义。这是我的课(它使用的是 Qt,但这无关紧要):
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;
};
它被称为:
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);
所以,这里的一切都工作正常,除了标记为抛出错误的行。我在这里要做的就是创建一个提供的类型和提供的参数的元组。
我尝试将导致错误的行替换为:
questionBoxElements = std::make_tuple<Ts...>(std::move(args...));
这会导致以前的错误消失,但是,然后我收到一个新错误(对于某些并非所有类型):
No matching function for call to 'move(Type1*&, Type2*&)'
我假设这是因为引发此错误的类型没有实现移动构造函数?那是对的吗?
解决方案
推荐阅读
- mongodb - db.collection.find().explain() 在 MongoDB 4.0 中不再输出性能细节
- php - 如果不将其存储在数据库中,则无法显示
- stress-testing - 使用压力ng来模拟工作量
- java - 如何对向量进行排序
> 将子项目组合在一起的多个元素? - image-processing - 使用图像作为不透明蒙版
- amazon-iam - 无法访问 AWS Elasticsearch 集群,IAM 策略问题
- c++ - 如何从派生类函数中调用虚函数
- c++ - 如何使用基于范围的 for 循环遍历本身就是 JSON 数组的 Rapidjson 文档?
- typescript - 在自己的初始化程序中引用的循环类型
- blazor - 如何将 Blazor 组件/视图加载到特定的 div 中