The muon g − 2 in two-Higgs-doublet models