是否可以在 C++ 20 中为概念完成删除关键字模板?

Is it possible to complete remove keyword template in C++ 20 for concepts?

例如使用 Visual Studio 16.3 和

/std:c++最新

这里声明的标志here我可以写。

#include <concepts>

template <std::integral T>
T plus1(T a) {
    return a + 1;
}


int main() {

    auto i = plus1(10);

}

但是我不会写

#include <concepts>

std::integral plus1(std::integral a) {
    return a + 1;
}


int main() {

    auto i = plus1(10);

}

但我读到 here 这应该是可能的。

Concepts TS 提供了所谓的 "terse syntax",它允许您通过在参数列表中使用概念而不是类型名称来隐式地将函数声明为模板。在尝试将 Concepts TS 纳入标准时,ISO C++ 委员会认为这是有争议的。他们想要一种通过查看函数声明来了解它是否是模板的方法。

经过一些来回,他们 came up with an alternate terse syntax:您使用 auto 推导(取自通用 lambda),受概念名称约束:

std::integral auto plus1(std::integral auto a) {
    return a + 1;
}

但是,目前大多数概念实现都实现了 Concepts TS 功能,更新的内容尚未实现。 VS 从来没有 Concepts TS 实现,他们明确表示他们还没有实现这种简洁的模板语法。

没有。仅在基本情况下。 在某些情况下,您可能需要,例如,精确类型。 例如,要进行转接呼叫,您可以编写

template <class ... TT>
void SomeFunc(TT && ... tt)
 {
  AnotherFunc( std::forward<TT>(tt)... );
 }