Swap

template <typename Assignable1,   typename Assignable2> _CCCL_HOST_DEVICE void swap(Assignable1 & a,   Assignable2 & b);

Functions

Function swap

template <typename Assignable1,   typename Assignable2> _CCCL_HOST_DEVICE void swap(Assignable1 & a,   Assignable2 & b); swap assigns the contents of a to b and the contents of b to a. This is used as a primitive operation by many other algorithms.

The following code snippet demonstrates how to use swap to swap the contents of two variables.

#include <thrust/swap.h>
...
int x = 1;
int y = 2;
thrust::swap(x,h);

// x == 2, y == 1

Template Parameters: Assignable: is a model of Assignable.

Function Parameters:

  • a The first value of interest. After completion, the value of b will be returned here.
  • b The second value of interest. After completion, the value of a will be returned here.