小编Ale*_*ter的帖子

解压枚举的可变参数包

更新:编辑以修复工作示例中的编译。

我想做类似下面的事情,以便该函数可以接受枚举类实例的列表或保存它们的结构,但是 的定义auto myFunc2<EList<Types...>>失败expected a constant not E::A

#include <cstdint>
#include <iostream>

enum class E {A = 0, B=1};
template<E... Types> struct tl2 {};
using my_list_2 = tl2<E::A>;

template <E ... Types>
auto myFunc2 = [] {
    std::cout << "Size: " << sizeof...(Types) << std::endl;     
};

template <template<E...> typename EList, E... Types>
auto myFunc2<EList<Types...>> = [] {
    std::cout << "Size: " << sizeof...(Types) << std::endl;     
};

int main() {
    myFunc2<E::A, E::B>();  // This call prints size of …
Run Code Online (Sandbox Code Playgroud)

c++ enums templates variadic

6
推荐指数
1
解决办法
92
查看次数

标签 统计

c++ ×1

enums ×1

templates ×1

variadic ×1