def __init__(self, *contents: cirq.OP_TREE, _flatten_contents: bool = True) -> None:
        """Constructs a moment with the given operations.

        Args:
            contents: The operations applied within the moment.
                Will be flattened and frozen into a tuple before storing.
            _flatten_contents: If True, use flatten_to_ops to convert
                the OP_TREE of contents into a tuple of Operation. If False,
                we skip flattening and assume that contents already consists
                of individual operations. This is used internally by helper
                methods to avoid unnecessary validation.

        Raises:
            ValueError: A qubit appears more than once.
        """
        self._operations = (
            tuple(op_tree.flatten_to_ops(contents))
            if _flatten_contents
            else cast(tuple['cirq.Operation'], contents)
        )
        self._sorted_operations: tuple[cirq.Operation, ...] | None = None

        # An internal dictionary to support efficient operation access by qubit.
        self._qubit_to_op: dict[cirq.Qid, cirq.Operation] = {}
        for op in self.operations:
            for q in op.qubits:
                # Check that operations don't overlap.
                if q in self._qubit_to_op:
                    raise ValueError(f'Overlapping operations: {self.operations}')
                self._qubit_to_op[q] = op

        self._measurement_key_objs: frozenset[cirq.MeasurementKey] | None = None
        self._control_keys: frozenset[cirq.MeasurementKey] | None = None
Constructs a moment with the given operations.

        Args:
            contents: The operations applied within the moment.
                Will be flattened and frozen into a tuple before storing.
            _flatten_contents: If True, use flatten_to_ops to convert
                the OP_TREE of contents into a tuple of Operation. If False,
                we skip flattening and assume that contents already consists
                of individual operations. This is used internally by helper
                methods to avoid unnecessary validation.

        Raises:
            ValueError: A qubit appears more than once.
        
cirq-core/cirq/circuits/moment.py