”工欲善其事,必先利其器。“—孔子《论语.录灵公》
首页 > 编程 > 除了``if''语句之外:在没有铸造的情况下,还可以在哪里使用明确的``bool''转换的类型?

除了``if''语句之外:在没有铸造的情况下,还可以在哪里使用明确的``bool''转换的类型?

发布于2025-01-24
浏览:320

Beyond `if` Statements: Where Else Can a Type with an Explicit `bool` Conversion Be Used Without Casting? 
上下文转换为bool允许的bool允许,而无需铸造

您的类定义了向布尔的明确转换,使您可以直接在条件语句中使用其实例't'。但是,此明确的转换提出了一个问题:在哪里可以将't'用作无铸件的布尔?

上下文转换方案

语句:

if(t) / * statement */;

!t t && t2 compile-pime tests:

static_assert(t); noexcept(t)

Algorithms and Concepts:

  • NullablePointer, predicate or comparator arguments in STL algorithms
    if (t)
      /* statement */;
  • 混合const and non-const转换操作员可能会导致混淆。
最新教程 更多>

免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。

Copyright© 2022 湘ICP备2022001581号-3