I recently tried to understand a C++ program that was written by somebody who I assume had a background in functional programming: For example, he had declared a closure class which he extensively used and which does somewhat resemble what is known as a closure in functional programming. Another class was called a guard, but I haven’t quite figured out yet what it is good for. It seems to have some sort of cleanup functionality attached to it.
The only language in which I have seen a concept called guard is Erlang, but that does not remotely look similar to the code I found. In what other languages does such a concept exist that the author of the C++ code may have alluded to?
To me it sounds like he was using RAII.
The class constructor/destructor is used to symetrically handle some form of resource allocation/release in an exception safe context (What Java programmers would call finally {} as the destructor is guranteed to be called.).
This is a very common C++ idiom and is ued extensively in modern C++.
Did the code look like this:
Here the guard is locking the lock in the constructor and unlocking the lock in the destructor.