I am trying to implement something similar to the Python with statement in C++. As I plan to use it mainly with Qt-OpenGL the methods are called bind and release (in Python __enter__, __exit__). Code I came up with: header: cpp: Usage: Questions: Needing class A and class B feels a bit clumsy. Is there a better alternative? Are there