Use enable_if and templating to reduce the amount of duplicated code in dot_product vari's