c++windows-runtimewrl

Calling Microsoft::WRL::Make for a constructor with more than 9 arguments


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)


Solution

  • FWIW, here's my current working solution:

    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))...)
    {
    }
    

    Constructed with

    auto ptr = Make<MyClass>(std::forward_as_tuple(...));
    

    Far from ideal, but worst case scenario it'll do...