• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function
    <atomic>

    std::atomic_ref::コンストラクタ

    explicit atomic_ref(T& obj);                            // (1) C++20
    constexpr explicit atomic_ref(T& obj);                  // (1) C++26
    
    atomic_ref(const atomic_ref& other) noexcept;           // (2) C++20
    constexpr atomic_ref(const atomic_ref& other) noexcept; // (2) C++26
    

    概要

    • (1) : objを参照して*thisにポインタとして保持する
    • (2) : コピーコンストラクタ。otherが参照するオブジェクトを*thisもまた参照する

    事前条件

    • 参照するオブジェクトがメンバ定数のアライメント値required_alignmentにアライメントされていること

    例外

    投げない

    備考

    • デフォルトコンストラクタは定義されない

    #include <atomic>
    
    int main()
    {
      int value = 3;
    
      // valueを参照するatomic_refオブジェクトを構築
      std::atomic_ref<int> a{value};
    
      // コンストラクタの引数によって、
      // クラステンプレートのテンプレート引数を推論 (<int>を省略)
      std::atomic_ref b{value};
    
      // cとbで同じ値 (value) を参照
      std::atomic_ref c = b;
    }
    

    出力

    バージョン

    言語

    • C++20

    処理系

    参照