标准库标头 <contracts> (C++26)

来自cppreference.com
< cpp‎ | header


 
 
标准库头
通用工具
<any> (C++17)
<bitset>
<bit> (C++20)
<charconv> (C++17)
<expected> (C++23)
<format> (C++20)
<functional>
<optional> (C++17)
<stdbit.h> (C++26)
<tuple> (C++11)
<typeindex> (C++11)
<utility>
<variant> (C++17)
容器
<array> (C++11)
<deque>
<flat_map> (C++23)
<flat_set> (C++23)
<forward_list> (C++11)
<hive> (C++26)
<inplace_vector> (C++26)   
<list>
<map>
<mdspan> (C++23)
<queue>
<set>
<span> (C++20)
<stack>
<unordered_map> (C++11)
<unordered_set> (C++11)
<vector>
迭代器
<iterator>
范围
<generator> (C++23)
<ranges> (C++20)
 

此标头是语言支持库的一部分。

目录

类型

在命名空间 std::contracts 定义
违背的契约断言的种类
(枚举) [编辑]
发生契约违背时的求值语义
(枚举) [编辑]
导致契约违背的原因
(枚举) [编辑]
持有契约违背信息的类型
(类) [编辑]

函数

在命名空间 std::contracts 定义
调用默认的契约违背处理函数
(函数) [编辑]

[编辑] 概要

// 全部为独立
namespace std::contracts {
 
  enum class assertion_kind : /* 未指明 */ {
    pre = 1,
    post = 2,
    assert = 3
  };
 
  enum class evaluation_semantic : /* 未指明 */ {
    ignore = 1,
    observe = 2,
    enforce = 3,
    quick_enforce = 4
  };
 
  enum class detection_mode : /* 未指明 */ {
    predicate_false = 1,
    evaluation_exception = 2
  };
 
  // 类 contract_violation
  class contract_violation;
 
  void invoke_default_contract_violation_handler(const contract_violation&);
}

[编辑] std::contracts::contract_violation

namespace std::contracts {
  class contract_violation
  {
    // 没有用户可访问的构造函数
  public:
    contract_violation(const contract_violation&) = delete;
    contract_violation& operator=(const contract_violation&) = delete;
    /* 见描述 */ ~contract_violation();
    const char* comment() const noexcept;
    contracts::detection_mode detection_mode() const noexcept;
    exception_ptr evaluation_exception() const noexcept;
    bool is_terminating() const noexcept;
    assertion_kind kind() const noexcept;
    source_location location() const noexcept;
    evaluation_semantic semantic() const noexcept;
  };
}