c++ - header 中的 "inline"是否需要 "void f(auto) {}"?

标签 c++ templates inline auto c++20

考虑

template<typename T>
inline void f(T) {} // "inline" can be safely removed.

inline void f(auto) {} // Can "inline" also be safely removed?

根据 C++ 标准,能否 inline 在后一种情况下可以安全删除?

最佳答案

来自 [dcl.fct]/18 :

An abbreviated function template is a function declaration that has one or more generic parameter type placeholders ([dcl.spec.auto]). An abbreviated function template is equivalent to a function template ([temp.fct]) whose template-parameter-list includes one invented type template-parameter for each generic parameter type placeholder of the function declaration, in order of appearance.

添加了强调。这不会为 inline 不是默认设置留出很大的回旋余地。

关于c++ - header 中的 "inline"是否需要 "void f(auto) {}"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61174695/

相关文章:

javascript - 遍历函数调用

c++ - 谁能给我_dupenv_s的示例代码?

c++ - 如何在 C++ 中的变量中存储任何类型的函数?

c++ - 从数据库中搜索时间复杂度为 O(1)\O(log n) 的行

C++ 模板成员函数已定义为相同类型

kotlin - 了解Kotlin中的内联类

c++ - 是否允许将指向模板函数的指针传递给 C 库? (作为回调)

c++ - GCC 可以从最终输出中消除什么样的死代码?

CKEDITOR 内联编辑器工具栏上的文本选择

c++ - 内联文件之间的循环依赖