Not sure when it was added, but I believe that ros::topic::waitForMessage(..) (api docs) is a much more elegant solution when only needing a single message.
See #q270298 for an example that shows how to use ros::topic::waitForMessage(..).