Use lambdas to avoid a loop and static_casts.