title: Implement Observer Pattern in C++
body: <p>The observer pattern can be really useful in event-driven systems. Here's how it might be implemented in two languages: </p>
  
  <p><strong>Java</strong></p>
  
  <p>Use an AOP library or byte-code engineering (BCEL, cglib, asm, etc) to create a sub-class on the fly. Any calls to the getter or setter of an observed property notifies any attached observers. </p>
  
  <p><strong>Objective-C</strong></p>
  
  <p>This is similar to Java - uses isa swizzling to create a sub-class on the fly. Any calls to an observed property notifies attached observers. Interestingly, in Objective-C we can swizzle back to the original class without the wrapped property methods, if all observers are removed. Whereas in Java a class is typically loaded once, so you're always notifying a (possibly empty) set of observers. </p>
  
  <p><strong>How about C++?</strong> </p>
  
  <p>With limited reflection in C++, it would be difficult to use the above approaches. What is the "best" (by that I mean typical or defacto-standard) approach in C++? Is there any way to avoid the boiler-plate code like in the Java and Objective-C implementations that I referenced above? Perhaps using C++ meta-programming features?</p>