I have a ScopedLock
class which can help to release lock automatically when running out of scope.
However, the problem is: Sometimes team members write invalid
No, unfortunately there is no way to do this, as I explored in a blog post last year.
In it, I concluded:
I guess the moral of the story is to remember this story when using
scoped_lock
s.
You can try to force all programmers in your team to use a macro, or a range-for trick, but then if you could guarantee that in every case then you'd be able to guarantee catching this bug in every case also.
You are looking for a way to programmatically catch this specific mistake when it's made, and there is none.