如何调用模板化运算符()()?

fbr*_*eto 1 c++ templates compiler-errors operators

我有一个看起来像这样的结构:

struct foo_t
{
    template <std::size_t x, std::size_t y>
    std::size_t operator()() const
    { return /*something dealing with x and y*/; }
};
Run Code Online (Sandbox Code Playgroud)

该定义似乎编译得很好,但我怎么称呼它?我似乎无法通过编译器得到任何东西:

foo_t foo;
foo<3, 3>(); // ERROR: Compiler seems to think I'm asking for "foo < 3 ..."
Run Code Online (Sandbox Code Playgroud)

ild*_*arn 6

这很难看,但......

foo_t foo;
foo.operator()<3, 3>();
Run Code Online (Sandbox Code Playgroud)

在线演示.

  • +1.每当我看到这样的代码片段时,我都为编译器实现者感到遗憾:-)不是模板让我如此多,因为字符串`()<3,3>()`具有有效的上下文. (6认同)
  • 我害怕丑陋...如果它有效,我认为它有效. (2认同)