为可变元组构造参数堆栈
Construct parameter stack for variadic tuple
我有一个包含可变元组的 class,但需要自己构建参数堆栈。谁能告诉我该怎么做?元组元素没有默认构造函数。
简化后的代码如下所示:
#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;
}
#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;
};
你可以这样做:
template<class... ARGS>
struct foo : base
{
foo() : t(elem<ARGS>(this)...) {}
std::tuple<elem<ARGS>...> t;
};
我有一个包含可变元组的 class,但需要自己构建参数堆栈。谁能告诉我该怎么做?元组元素没有默认构造函数。
简化后的代码如下所示:
#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;
}
#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;
};
你可以这样做:
template<class... ARGS>
struct foo : base
{
foo() : t(elem<ARGS>(this)...) {}
std::tuple<elem<ARGS>...> t;
};