Add a template for bijections to/from primitives

RE #833