次の方法で共有


weak_ptr::expired

所有権の有効期限が切れているかどうかをテストします。

bool expired() const;

解説

このメンバー関数は、*this の有効期限が切れている場合は true を返します。それ以外の場合は false を返します。

使用例

 

// std_tr1__memory__weak_ptr_expired.cpp 
// compile with: /EHsc 
#include <memory> 
#include <iostream> 
 
struct deleter 
    { 
    void operator()(int *p) 
        { 
        delete p; 
        } 
    }; 
 
int main() 
    { 
    std::weak_ptr<int> wp; 
 
     { 
    std::shared_ptr<int> sp(new int(10)); 
    wp = sp; 
    std::cout << "wp.expired() == " << std::boolalpha 
        << wp.expired() << std::endl; 
    std::cout << "*wp.lock() == " << *wp.lock() << std::endl; 
     } 
 
// check expired after sp is destroyed 
    std::cout << "wp.expired() == " << std::boolalpha 
        << wp.expired() << std::endl; 
    std::cout << "(bool)wp.lock() == " << std::boolalpha 
        << (bool)wp.lock() << std::endl; 
 
    return (0); 
    } 
 
  

必要条件

ヘッダー: <memory>

名前空間: std

参照

関連項目

weak_ptr クラス