Added template function select_if() in variant.h; Unit-tested.

why do you need to cast n_samples to int ?