Template-based automatic differentiation library