  We present a scheme for a universal device which can be programmed by quantum
states to approximate a chosen projective measurement to a given precision. Our
scheme can be viewed as an extension of the swap test to the instance where one
state is supplied many times. As such, it has many potential applications given
the variety of quantum information tasks which make use of the swap test. In
particular, we show that our scheme is optimal for state discrimination under
the one-sided error requirement, and optimally approximates any projective
measurement. Furthermore, we propose a practical implementation of our scheme
with passive linear optics, which involves a simple interferometer composed
only of balanced beam splitters.
