Works with compile-time composite functions (tested with arc).  Only compiles on g++ 4.8, but crashed on one line so there's a small workaround right now.
Cleaned up and checked object reference counting management.  Untested though.
Fixed up and tested samples.