Enhancement of superconductivity at the onset of charge-density-wave order in a metal