I need to have a common counter in my class (to call some function when the counter goes to zero). I can use shared_ptr<char>with a deleter for this, but this approach has the overhead of highlighting the unnecessary charand storing a pointer to it.
Basically, I need a reference counting part shared_ptr. I do not see how I can use shared_ptrand avoid this overhead.
Is there a portable C ++ 11 implementation (i.e., only using standard C ++ 11 and stdexplicit mutexes, etc.) of common counters?
PS. The counter is not unique to the entire class. I can have objects a1, a2, a3 of my class that use the same counter. And b1, b2, b3, which use different counters. Therefore, when the last of a1, a2, a3 goes out of scope, something should happen (related to a1, a2, a3). When the last of b1, b2, b3 goes out of scope, something must happen (related to b1, b2, b3).
thanks
source
share