gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 14:16:02 26 4
gpt4 key购买 nike

考虑

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com