Use macro to simplify swap implementation