We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
T240102 What does the ...... mean in C++? https://ift.tt/672Wmrd Li Miu
不知大家是否遇到过这样的代码:
参数包后面紧跟着 6 个 .,一般不是用 ... 来扩展参数包吗?这是什么鬼东西?
.
...
这个其实可以称为 Two ellipsis operators(非正式称谓),虽说极其罕见,但却是 C++11 标准的一部分,见 [dcl.fct]/3:
parameter-declaration-clause: parameter-declaration-listopt …opt parameter-declaration-list , …
也就是说,它其实是 ..., ... 的省略写法。以下这三种写法完全等价:
..., ...
而 ...... 是最简洁的写法,多为使用。那么它有什么作用呢?
......
这又是向后兼容 C 的产物,第一个 ... 用于扩展 C++ 可变模板参数包,第二个 ... 则用于匹配 C Variadic functions[1] 中的旧式变参。
主要目的就在于识别 C Variadic functions,举个例子:
早期 std::is_function[2] 的实现就使用这一手法来识别 C Variadic functions。
std::is_function
因此,它才能识别 printf/fprintf 这些旧式可变函数。不过,早期这种实现太过麻烦,如今利用概念直接求解,变得极为简单:
printf/fprintf
</div></div></div></div><br>
The text was updated successfully, but these errors were encountered:
No branches or pull requests
T240102 What does the ...... mean in C++?
https://ift.tt/672Wmrd
Li Miu
不知大家是否遇到过这样的代码:
参数包后面紧跟着 6 个
.
,一般不是用...
来扩展参数包吗?这是什么鬼东西?这个其实可以称为 Two ellipsis operators(非正式称谓),虽说极其罕见,但却是 C++11 标准的一部分,见 [dcl.fct]/3:
也就是说,它其实是
..., ...
的省略写法。以下这三种写法完全等价:而
......
是最简洁的写法,多为使用。那么它有什么作用呢?这又是向后兼容 C 的产物,第一个
...
用于扩展 C++ 可变模板参数包,第二个...
则用于匹配 C Variadic functions[1] 中的旧式变参。主要目的就在于识别 C Variadic functions,举个例子:
早期
std::is_function
[2] 的实现就使用这一手法来识别 C Variadic functions。因此,它才能识别
printf/fprintf
这些旧式可变函数。不过,早期这种实现太过麻烦,如今利用概念直接求解,变得极为简单:via CppMore https://www.cppmore.com
February 12, 2025 at 03:55PM
The text was updated successfully, but these errors were encountered: