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

Update item15.md #191

Closed
wants to merge 1 commit into from
Closed

Update item15.md #191

wants to merge 1 commit into from

Conversation

laiqun
Copy link
Contributor

@laiqun laiqun commented Jul 13, 2024

No description provided.

@@ -142,7 +142,18 @@ constexpr auto reflectedMid = //reflectedMid的值
本条款的建议是尽可能的使用`constexpr`,现在我希望大家已经明白缘由:`constexpr`对象和`constexpr`函数可以使用的范围比non-`constexpr`对象和函数大得多。使用`constexpr`关键字可以最大化你的对象和函数可以使用的场景。

还有个重要的需要注意的是`constexpr`是对象和函数接口的一部分。加上`constexpr`相当于宣称“我能被用在C++要求常量表达式的地方”。如果你声明一个对象或者函数是`constexpr`,客户端程序员就可能会在那些场景中使用它。如果你后面认为使用`constexpr`是一个错误并想移除它,你可能造成大量客户端代码不能编译。(为了debug或者性能优化而添加I/O到一个函数中这样简单的动作可能就导致这样的问题,因为I/O语句一般不被允许出现在`constexpr`函数里)“尽可能”的使用`constexpr`表示你需要长期坚持对某个对象或者函数施加这种限制。
```cpp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

英文版没有出现此处代码?

Copy link
Contributor Author

@laiqun laiqun Jul 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

读的时候感觉有点疑惑,所以找ChatGPT添加了一份demo code。解释为啥编译不过。

@y1yang0 y1yang0 closed this Aug 19, 2024
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

Successfully merging this pull request may close these issues.

2 participants