Syntax help. Template operator() in template function object

79 views Asked by At

What is the proper syntax I need to run what I'm trying to run in main() below?

#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
}
1

There are 1 answers

3
rlbond On BEST ANSWER

I don't think you can manually specify template arguments for operator overloads. However, you can write

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