• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

    最終更新日時(UTC):
    が更新

    履歴 編集

    class
    <stop_token>

    std::nostopstate

    namespace std {
      struct nostopstate_t {
        explicit nostopstate_t() = default;
      };
    
      inline constexpr nostopstate_t nostopstate{};
    }
    

    概要

    nostopstate_t型とその値nostopstateは、停止状態を扱わないstop_sourceを構築するためのタグである。
    stop_sourceクラスのコンストラクタにnostopstateを渡すと、そのstop_sourceは停止要求を扱うためのリソースを確保せず、停止要求を作成したりstop_tokenクラスと停止状態を共有したりできない状態になる。

    #include <cassert>
    #include <stop_token>
    
    int main()
    {
      std::stop_source ss1;
      std::stop_source ss2(std::nostopstate);
    
      assert(ss1.stop_possible() == true);
      assert(ss2.stop_possible() == false);
    
      std::stop_token st1 = ss1.get_token();
      std::stop_token st2 = ss2.get_token();
    
      assert(st1.stop_possible() == true);
      assert(st2.stop_possible() == false);
    }
    

    出力

    バージョン

    言語

    • C++20

    処理系