0

Microsoft::WRL::Make seems to be defined with a maximum of 9 arguments that will get forwarded to the object's constructor. std::tuple is an obvious solution, but far from ideal. Is there a more elegant way of solving this problem?

If any maintainers of WRL are lurking around, please add variadic template support to Make (as well as RuntimeClass, etc. while you're at it)

4

1 回答 1

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(...));

远非理想,但最坏的情况下它会做......

于 2016-05-14T11:15:19.617 回答