Namespaces
Variants

boolean-testable

From cppreference.net
template < class B >
concept __boolean_testable_impl = std:: convertible_to < B, bool > ;
(1) (C++20 起)
( 仅用于说明* )
template < class B >

concept boolean - testable =
__boolean_testable_impl < B > &&
requires ( B && b ) {
{ ! std:: forward < B > ( b ) } - > __boolean_testable_impl ;

} ;
(2) (C++20 起)
( 仅用于说明* )

仅用于阐述的概念 boolean-testable 规定了可转换为 bool 的表达式要求,这些表达式需满足逻辑运算符的常规行为(包括 短路求值 ),即使涉及两个不同的 boolean-testable 类型时亦然。

形式上,要建模仅用于阐述的概念 __boolean_testable_impl ,该类型不得定义任何成员 operator && operator || ,且通过 实参依赖查找 不可见任何有效的非成员 operator && operator || 。此外,给定表达式 e 使得 decltype ( ( e ) ) B ,仅当满足 bool ( e ) == ! bool ( ! e ) 时,才建模 boolean-testable 概念。

等值保持性

标准库概念的 requires 表达式 中声明的表达式必须满足 等值保持 要求(除非另有说明)。

注释

符合 boolean-testable 要求的类型示例包括 bool std::true_type std:: bitset < N > :: reference 以及 int *

参考文献

  • C++23 标准 (ISO/IEC 14882:2024):
  • 18.5.2 布尔可测试性 [concept.booleantestable]
  • C++20 标准 (ISO/IEC 14882:2020):
  • 18.5.2 布尔可测试性概念 [concept.booleantestable]