SWAP gate implementation using CUDA-Q. The example prepares $\lvert 10\rangle$ and applies SWAP to produce $\lvert 01\rangle$.
// Compile: nvq++ main.cpp -o main // Run: ./main #include <cudaq.h> struct kernel { __qpu__ void operator()() { cudaq::qvector<2> q; x(q[0]); // q[0]=|1>, q[1]=|0> => |10> swap(q[0], q[1]); // |10> -> |01> mz(q); } }; int main() { auto counts = cudaq::sample(kernel{}); counts.dump(); // 100% |01> }