The promise could be deallocated before promise.set_value() had returned, which apparently caused an invalid read on some implementations. By moving the promise declaration up the stack, we ensure that the map is deallocated first, and therefore the map thread is joined, before the promise is deallocated.