<分区>
在某些情况下,我希望有某种基于时间的智能指针,例如缓存一些庞大的对象,但如果不使用它会在一定时间后自动释放。当指针被触摸(解除引用)时,倒计时将重新开始,如果您需要在计算期间“锁定”事件对象,您也可以停止倒计时。像这样的东西:
timed_ptr<Type,30> p = new Type(); \\object is deleted after 30 seconds, and pointer set to a checkable 'null' state
...
p.stop_count_down();
// do something with the object, guaranteed it won't expire while we still need it.
p.start_count_down();
boost 或其他库中是否存在此类内容?