pre*_*eys 1 c++ templates functor c++11
我需要运行正在尝试在main()下面运行的语法的正确语法是什么?
#include <iostream>
#include <vector>
template <int... Is>
void foo() {
std::vector<int> v{Is...};
for (int x : v) std::cout << x << ' ';
}
template <int... Is>
struct Foo {
template <typename T, typename... Ts>
void operator()() const {
std::cout << sizeof(T) << ' ' << sizeof...(Ts) << '\n';
foo<Is...>();
}
};
int main() {
// Foo<0,1,2>()<bool, char, long>();
Foo<0,1,2> f;
f<bool, char, long>(); // Won't compile
}
Run Code Online (Sandbox Code Playgroud)
我认为您不能手动为运算符重载指定模板参数.但是,你可以写
f.operator()<bool, char, long>();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
66 次 |
| 最近记录: |