Cavity functions and association in models for weak electrolytes and sticky hard spheres