2015-06-22 11:23:00 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <atomic>
|
2016-02-29 15:10:30 +01:00
|
|
|
#include <functional>
|
2015-06-22 11:23:00 +02:00
|
|
|
|
2015-06-25 16:46:59 +02:00
|
|
|
typedef std::atomic<unsigned long> counter;
|
2015-06-22 11:23:00 +02:00
|
|
|
|
|
|
|
struct MaintainCount
|
|
|
|
{
|
|
|
|
counter & c;
|
|
|
|
MaintainCount(counter & c) : c(c) { c++; }
|
2016-02-29 15:10:30 +01:00
|
|
|
MaintainCount(counter & c, std::function<void(unsigned long)> warn) : c(c)
|
|
|
|
{
|
|
|
|
warn(++c);
|
|
|
|
}
|
2015-08-17 13:50:41 +02:00
|
|
|
~MaintainCount() { auto prev = c--; assert(prev); }
|
2015-06-22 11:23:00 +02:00
|
|
|
};
|