Hao*_*hun 5 c++ c++17 nodiscard
我想将一个类标记为 nodiscard,但将某个函数的返回值排除在 nodiscard 要求之外。这是我的目标:
enum class [[nodiscard]] Result {
OK1,
OK2,
ERROR,
};
[[ok-to-discard]] // This attribute is made up to illustrate my need.
Result doSomethingThatCannotFail() {
// The function can return OK1 or OK2, but the caller may or may not care.
// The function cannot return ERROR.
// Therefore, it's OK to discard this particular Result return value,
// even though in general Result should not be ignored.
}
Run Code Online (Sandbox Code Playgroud)
我不认为在每个调用站点添加 ok-to-discard 是一个好主意(这由 如何故意丢弃 [[nodiscard]] 返回值? 涵盖):
| 归档时间: |
|
| 查看次数: |
261 次 |
| 最近记录: |