http://code.activestate.com/recipes/578246-stl-writer/