apply()/unpack(): new simpler implementation

This will hopefully also compile cleanly with clang on MacOSX...