Electron and muon g−2 anomalies in general flavor conserving two-Higgs-doublet models