有时我需要一种基于时间的智能指针,例如缓存某些庞大的对象,但如果在一定时间内未使用,则自动释放它。当触摸(解引用)指针时,倒计时重新启动,并且如果您需要“锁定”对象以进行计算,则还可以停止倒计时。类似于:
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或其他库中是否存在?