<future> 注释14:函 _Make_associated_state (Alloc& ),promise<Y> 的析构函数 ~promise ( ) 不会导致进程异常退出,

(44)函 _Make_associated_state (Alloc& ), 本函数返回在堆区创建的 _Associated_state<_Ty> 对象 的地址。本函数用于promise 的源代码中:

// construct an _Associated_state object with an allocator  用分配器构造 _Associated_state 对象
template <class _Ty, class _Alloc>  
_Associated_state<_Ty>*             // 注意本函数的返回值即可,在堆区创建 _Associated_state<_Ty> 对象
_Make_associated_state(const _Alloc& _Al) 
{
    using _Delty = _State_deleter<_Ty, _Associated_state<_Ty>, _Alloc>;
    using _Aldelty = _Rebind_alloc_t<_Alloc, _Delty>;                  //= _Alloc< _Delty >  凭经验
    using _Alstate = _Rebind_alloc_t<_Alloc, _Associated_state<_Ty>>;  //= _Alloc< _Associated_state<_Ty> > 

    _Aldelty _Del_alloc(_Al);   // 产生一个删除器
    _Alstate _State_alloc(_Al); // 用指定的分配器产生一个 _Associated_state<_Ty> 对象
    auto _Del = _Make_unique_alloc(_Del_alloc, _Al);                  //   _Del 和 _Res 是 unique_ptr 指针
    auto _Res = _Make_unique_alloc(_State_alloc, _Unfancy(_Del.get()));
/*
template <class _Ty, class _Dx >
class unique_ptr {      _Compressed_pair<_Dx, pointer> _Mypair;
    pointer get() { return _Mypair._Myval2; }
    pointer release() noexcept { return _STD exchange(_Mypair._Myval2, nullptr); }
};
*/
    (void)_Del.release();       // ownership of _Del.get() now transferred to _Res
    return _Unfancy(_Res.release()); // ownership transferred to caller
/*
template <class _Ptrty> // converts from a fancy pointer to a plain pointer
auto _Unfancy(_Ptrty _Ptr) noexcept { return _STD addressof(*_Ptr); } // 从智能指针转换为裸指针

template <class _Ty>    // do nothing for plain pointers
_Ty* _Unfancy(_Ty* _Ptr)   noexcept { return _Ptr;  }
*/
}

(45)promise 的析构函数 ~promise ( ) 不会导致进程异常退出, 测试一下:

在这里插入图片描述

++ 测试 :

在这里插入图片描述

(46)

谢谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zhangzhangkeji

谢谢支持

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值