【问题标题】:C++20: generate type from given variadic typesC++20:从给定的可变参数类型生成类型
【发布时间】:2021-05-03 15:33:01
【问题描述】:

可以说,我有一个可以增长的可变参数类型列表 例如

#define MY_TYPES  void, float, int, vector<long>, ..... 

我正在寻找在编译时以通用方式在 c++17/20 中生成这些类型定义的方法,例如

#define to_tuple(MY_TYPES) ==> std::tuple<future<void>, future<float>, future<int>....>
using tupleType = decltype(to_tuple<ALL_TYPES>); // this can be then used in struct as a member.

struct foo {
   ...
   ...
   tupleType tups;
}

或者,如果这可以使用模板元编程来完成?

感谢您的帮助。

【问题讨论】:

标签: c++ c-preprocessor c++20 variadic-macros fold-expression


【解决方案1】:
template <typename ...P>
using tuple_of_futures_t = std::tuple<std::future<P>...>;

using X = tuple_of_futures_t<void, float, int, std::vector<long>>;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-02-05
    • 1970-01-01
    • 1970-01-01
    • 2019-10-17
    • 2014-12-16
    • 2019-06-24
    • 2021-06-14
    相关资源
    最近更新 更多