// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved. // SPDX-License-Identifier: Apache-2.0 /*! \file swap.h * \brief Functions for swapping the value of elements */ #pragma once #include #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) # pragma GCC system_header #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) # pragma clang system_header #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) # pragma system_header #endif // no system header #include #include THRUST_NAMESPACE_BEGIN using ::cuda::std::swap; /*! \addtogroup copying * \{ */ /*! \p swap_ranges swaps each of the elements in the range [first1, last1) * with the corresponding element in the range [first2, first2 + (last1 - first1)). * That is, for each integer \c n such that 0 <= n < (last1 - first1), it swaps * *(first1 + n) and *(first2 + n). The return value is * first2 + (last1 - first1). * * The algorithm's execution is parallelized as determined by \p exec. * * \param exec The execution policy to use for parallelization. * \param first1 The beginning of the first sequence to swap. * \param last1 One position past the last element of the first sequence to swap. * \param first2 The beginning of the second sequence to swap. * \return An iterator pointing to one position past the last element of the second * sequence to swap. * * \tparam DerivedPolicy The name of the derived execution policy. * \tparam ForwardIterator1 is a model of Forward * Iterator, and \p ForwardIterator1's \c value_type must be convertible to \p ForwardIterator2's \c value_type. * \tparam ForwardIterator2 is a model of Forward * Iterator, and \p ForwardIterator2's \c value_type must be convertible to \p ForwardIterator1's \c value_type. * * \pre \p first1 may equal \p first2, but the range [first1, last1) shall not overlap the range [first2, * first2 + (last1 - first1)) otherwise. * * The following code snippet demonstrates how to use \p swap_ranges to * swap the contents of two \c thrust::device_vectors using the \p thrust::device execution * policy for parallelization: * * \code * #include * #include * #include * ... * thrust::device_vector v1(2), v2(2); * v1[0] = 1; * v1[1] = 2; * v2[0] = 3; * v2[1] = 4; * * thrust::swap_ranges(thrust::device, v1.begin(), v1.end(), v2.begin()); * * // v1[0] == 3, v1[1] == 4, v2[0] == 1, v2[1] == 2 * \endcode * * \see https://en.cppreference.com/w/cpp/algorithm/swap_ranges * \see \c swap * * \verbatim embed:rst:leading-asterisk * .. versionadded:: 2.2.0 * \endverbatim */ template _CCCL_HOST_DEVICE ForwardIterator2 swap_ranges( const thrust::detail::execution_policy_base& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2); /*! \p swap_ranges swaps each of the elements in the range [first1, last1) * with the corresponding element in the range [first2, first2 + (last1 - first1)). * That is, for each integer \c n such that 0 <= n < (last1 - first1), it swaps * *(first1 + n) and *(first2 + n). The return value is * first2 + (last1 - first1). * * \param first1 The beginning of the first sequence to swap. * \param last1 One position past the last element of the first sequence to swap. * \param first2 The beginning of the second sequence to swap. * \return An iterator pointing to one position past the last element of the second * sequence to swap. * * \tparam ForwardIterator1 is a model of Forward * Iterator, and \p ForwardIterator1's \c value_type must be convertible to \p ForwardIterator2's \c value_type. * \tparam ForwardIterator2 is a model of Forward * Iterator, and \p ForwardIterator2's \c value_type must be convertible to \p ForwardIterator1's \c value_type. * * \pre \p first1 may equal \p first2, but the range [first1, last1) shall not overlap the range [first2, * first2 + (last1 - first1)) otherwise. * * The following code snippet demonstrates how to use \p swap_ranges to * swap the contents of two \c thrust::device_vectors. * * \code * #include * #include * ... * thrust::device_vector v1(2), v2(2); * v1[0] = 1; * v1[1] = 2; * v2[0] = 3; * v2[1] = 4; * * thrust::swap_ranges(v1.begin(), v1.end(), v2.begin()); * * // v1[0] == 3, v1[1] == 4, v2[0] == 1, v2[1] == 2 * \endcode * * \see https://en.cppreference.com/w/cpp/algorithm/swap_ranges * \see \c swap * * \verbatim embed:rst:leading-asterisk * .. versionadded:: 2.2.0 * \endverbatim */ template ForwardIterator2 swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2); /*! \} // copying */ THRUST_NAMESPACE_END #include