Comparison of scalar and vector types factored out into an overloadable cast function.