The phase diagram for coexisting d-wave superconductivity and charge-density waves: cuprates and beyond