更新:编辑以修复工作示例中的编译。
我想做类似下面的事情,以便该函数可以接受枚举类实例的列表或保存它们的结构,但是 的定义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)