为变元元组构造参数堆栈
Construct parameter stack for variadic tuple
我有一个包含可变元组的类,但需要自己构造参数堆栈。有人能告诉我怎么做吗?元组元素没有默认构造函数。
简化的代码如下所示:
#include <tuple>
struct base {};
template<class T>
struct elem
{
elem(base*){}
elem() = delete;
};
template<class... ARGS>
struct foo : base
{
foo() : t( /* initialize all elems with this */) {}
std::tuple<elem<ARGS>...> t;
};
int main()
{
foo<int, double> f;
}
您可以执行以下操作:
template<class... ARGS>
struct foo : base
{
foo() : t(elem<ARGS>(this)...) {}
std::tuple<elem<ARGS>...> t;
};
#include <tuple>
template <typename... ARGS>
struct foo : base
{
foo() : t(get_this<ARGS>()...) {}
template <typename>
foo* get_this() { return this; }
std::tuple<elem<ARGS>...> t;
};
DEMO
相关文章:
- 如何使用主参数添加更多堆栈?
- 如何从 x64 程序集中的堆栈中获取参数?
- C++ 参数堆与堆栈,基元类型的数组
- 将参数推送到调用堆栈 (C++) 的可移植方法
- 变量参数列表 后面的'const std::string&'弄乱了堆栈
- 评估虚拟堆栈中的可变参数
- 被调用方如何知道参数是通过寄存器而不是堆栈传递的
- 在 Myfile.exe 中0x00831D39时未处理的异常:0xC00000FD:堆栈溢出(参数:0x0000000
- 如何使用ABI调用过程在堆栈上正确传递Float参数
- C++17 使用选定的构造函数在堆栈中构造数组(每个数组条目的构造函数参数值相同)
- 通过参考数组传递分配的堆栈参数
- 系统堆栈中的两个函数的递归调用(将不同数量的数组作为参数传递)有什么区别
- 功能参数导致堆栈溢出
- 使用 windbg 查找不在堆栈顶部的函数的函数参数
- 参数列表太长了,而堆栈大小ID无限和命令大小约为300 kbyte
- 如何使用在另一个类的构造函数中的堆栈上接受参数的构造函数创建对象
- 指针函数参数已损坏,堆栈已损坏
- stl数据结构的堆栈上输出参数与返回值的效率
- 数组使用的堆栈(参数传递/返回)
- 为变元元组构造参数堆栈