Microsoft::WRL::Make
seems to be defined with a maximum of 9 arguments that will get forwarded to the object's constructor。 std::tuple
是一个明显的解决方案,但远非理想。有没有更优雅的方法来解决这个问题?
如果WRL的任何维护者都在潜伏,请向Make
(以及RuntimeClass
等添加可变参数模板支持,等等)
答案 0 :(得分:0)
FWIW,这是我目前的工作解决方案:
template <typename... Types>
MyClass(std::tuple<Types...> args) :
MyClass(args, std::make_integer_sequence<size_t, sizeof...(Types)>())
{
}
template <typename... Types, size_t... Indices>
MyClass(std::tuple<Types...>& args, std::integer_sequence<size_t, Indices...>) :
MyClass(std::get<Indices>(std::move(args))...)
{
}
用
构建auto ptr = Make<MyClass>(std::forward_as_tuple(...));
远非理想,但最糟糕的情况是它会......