def remove_all(gset, elem):
    """Removes every occurrence of ``elem`` from ``gset``.

    Returns the number of times ``elem`` was removed.
    """
    n = 0
    while True:
        try:
            remove_once(gset, elem)
            n = n + 1
        except RemoveError:
            return n