如何使用可变模板声明std::元组
How I declare a std::tuple using variadic templates?
也许我在这里很天真,但我认为应该编译以下代码:
template <typename ... T>
struct Test {
std::tuple<T> foo;
};
int main() {
struct Test<int, long> test;
return 0;
}
相反g++抱怨:
test.cpp:5: error: parameter packs not expanded with '...':
test.cpp:5: note: 'T'
我错过了什么?
您可以通过使用...
:扩展包来实现这一点
template <typename... T>
struct Test
{
std::tuple<T...> foo;
// ^^^^
};
相关文章:
- 在声明中合并两个常量"std::set"(不是在运行时)
- std::unordered_map 类型对象声明期间出现"field has incomplete type"错误
- std::带有前向声明的变体
- 如何在 C++ 中转发声明 std::set?
- 警告:忽略模板参数上的属性..在 std::unique_ptr (-wignore 属性)的声明中
- 为什么在不使用时在此处声明 std::unique_lock
- 如何使用模板声明"std::array" "using"
- C :如何声明std ::函数而无需创建成员函数以分配给它们
- 声明std ::配对时大小的写入无效
- 如何将值分配给没有值的声明 std::chrono::d uration
- 尚未声明“ std :: get_time”
- 如何用'n'维数组声明 std::vector?
- 如何匿名声明std::线程
- 在标头中正向声明std::size_t
- 如何在不使用 auto 的情况下声明 std::make_tuple 结果的类型
- 为什么预先声明 std::basic_string<T> 会破坏 boost::regex?
- 为什么在声明std::set时需要重复排序子程序
- 如何使用可变模板声明std::元组
- 如何声明std::unique_ptr以及它的用途
- 声明 std::map 迭代器会导致一个奇怪的错误