【发布时间】:2020-03-18 08:30:46
【问题描述】:
按照How can I have multiple parameter packs in a variadic template? 此处提供的一些解决方案,我希望将多个参数包应用于一个类并使用 CTAD 使该类更可用。
这是我想出的(在Coliru),但这给出了:
错误:类模板参数推导失败
这是我试过的代码:
// A template to hold a parameter pack
template < typename... >
struct Typelist {};
// Declaration of a template
template< typename TypeListOne
, typename TypeListTwo
>
struct Foo;
// A template to hold a parameter pack
template <typename... Args1, typename... Args2>
struct Foo< Typelist < Args1... >
, Typelist < Args2... >
>{
template <typename... Args>
struct Bar1{
Bar1(Args... myArgs) {
_t = std::make_tuple(myArgs...);
}
std::tuple<Args...> _t;
};
template <typename... Args>
struct Bar2{
Bar2(Args... myArgs) {
_t = std::make_tuple(myArgs...);
}
std::tuple<Args...> _t;
};
Bar1<Args1...> _b1;
Bar2<Args2...> _b2;
Foo(Bar1<Args1...>& b1, Bar2<Args2...>& b2) {
_b1 = b1;
_b2 = b2;
}
};
int main()
{
Foo{Foo::Bar1(1, 2.0, 3), Foo::Bar2(100, 23.4, 45)};
return 0;
}
【问题讨论】:
-
恕我直言,即使有演绎指南,编译器也无法理解
Foo::Bar1(1, 2.0, 3)。
标签: c++ templates c++17 variadic-templates