【问题标题】:Calling Microsoft::WRL::Make for a constructor with more than 9 arguments为具有超过 9 个参数的构造函数调用 Microsoft::WRL::Make
【发布时间】:2016-05-14 10:43:52
【问题描述】:

Microsoft::WRL::Make seems to be defined with a maximum of 9 arguments that will get forwarded to the object's constructorstd::tuple 是一个显而易见的解决方案,但远非理想。有没有更优雅的方法来解决这个问题?

如果有 WRL 的维护者在附近,请在Make(以及RuntimeClass 等)添加可变参数模板支持

【问题讨论】:

    标签: c++ windows-runtime wrl


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-22
      • 1970-01-01
      • 2015-02-03
      • 2022-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多