是否可以通过使用元组中包含的参数来初始化类的成员(或调用超类构造函数)?std::make_from_tuple()
请注意,我知道std::apply()
但它们不能在这种情况下使用。
考虑sometype
是不可复制的,不可默认构造的,不可移动的,不可分配的,没有其他任何东西。实例化它的唯一方法是使用作为std::tuple
. 这可以做到吗?
我的尝试失败了,因为显然“扩展模式不包含参数包”,尽管 index_sequence 生成应该是一个。
class node {
public:
sometype value;
template <typename... Args>
explicit node(const std::tuple<Args...>& args_tuple) :
value(
std::get<
std::index_sequence_for<Args...>{}
>(args_tuple)...
) {
}
};