语法帮助.模板函数对象中的模板运算符()

Syntax help. Template operator() in template function object

本文关键字:运算符 对象 帮助 函数 语法      更新时间:2023-10-16
我需要什么

正确的语法来运行我在下面的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
}
我认为

您无法手动为运算符重载指定模板参数。但是,你可以写

f.operator()<bool, char, long>();