Using take_while idiom.