Skip to content
New issue

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? #11969

Open
guevara opened this issue Feb 12, 2025 · 0 comments
Open

T240102 What does the ...... mean in C? #11969

guevara opened this issue Feb 12, 2025 · 0 comments

Comments

@guevara
Copy link
Owner

guevara commented Feb 12, 2025

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。

因此,它才能识别 printf/fprintf 这些旧式可变函数。不过,早期这种实现太过麻烦,如今利用概念直接求解,变得极为简单:

    </div></div></div></div><br>





via CppMore https://www.cppmore.com

February 12, 2025 at 03:55PM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant