且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

'auto'不允许在Clang的函数原型

更新时间:2023-11-09 20:32:22

我们从ISO C ++讨论邮件中看到: decltype(auto)parameters versus perfect forwarding non-lambdas的自动参数是概念lite ,因此不在C ++ 14中:

As we see from the ISO C++ discussion mailing: decltype(auto) parameters vs. perfect forwarding auto parameters of non-lambdas is part of concepts lite and therefore not in C++14:


clang是否正确感觉我们还没有汽车参数。

clang is correct in the sense that we don't yet have auto parameters. Concepts lite may bring those, but C++14 doesn't have them.

如果我们使用 -pedantic 标志与 gcc ,我们收到以下警告:

If we use the -pedantic flag with gcc we receive the following warning:

warning: ISO C++ forbids use of 'auto' in parameter declaration [-Wpedantic]
  auto foo(auto bar) { return bar; }
           ^

所以这看起来像一个扩展。

So this looks like an extension.

正如dyp所指出的,多态lambdas 确实允许使用C ++ 14并允许自动参数,例如:

As dyp pointed out, polymorphic lambdas did make it into C++14 and do allow auto parameters, an example taken from the paper:

// 'Identity' is a lambda that accepts an argument of any type and
// returns the value of its parameter.
auto Identity = [](auto a) { return a; };
int three = Identity(3);
char const* hello = Identity("hello");

这是您希望在您的示例中实现的功能。

Which is incidentally the same functionality you want to implement in your example.