thrust/functional.h
File members: thrust/functional.h
/*
* Copyright 2008-2018 NVIDIA Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <thrust/detail/config.h>
#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 <thrust/detail/functional/actor.h>
#include <cuda/functional>
#include <cuda/std/functional>
#include <functional>
THRUST_NAMESPACE_BEGIN
using ::cuda::std::divides;
using ::cuda::std::minus;
using ::cuda::std::modulus;
using ::cuda::std::multiplies;
using ::cuda::std::negate;
using ::cuda::std::plus;
template <typename T = void>
struct square
{
_CCCL_EXEC_CHECK_DISABLE
_CCCL_HOST_DEVICE constexpr T operator()(const T& x) const
{
return x * x;
}
};
template <>
struct square<void>
{
using is_transparent = void;
_CCCL_EXEC_CHECK_DISABLE
template <typename T>
_CCCL_HOST_DEVICE constexpr T operator()(const T& x) const noexcept(noexcept(x * x))
{
return x * x;
}
};
using ::cuda::std::equal_to;
using ::cuda::std::greater;
using ::cuda::std::greater_equal;
using ::cuda::std::less;
using ::cuda::std::less_equal;
using ::cuda::std::not_equal_to;
using ::cuda::std::logical_and;
using ::cuda::std::logical_not;
using ::cuda::std::logical_or;
using ::cuda::std::bit_and;
using ::cuda::std::bit_or;
using ::cuda::std::bit_xor;
// TODO(bgruber): this version can also act as a functor casting to T making it not equivalent to ::cuda::std::identity
template <typename T = void>
struct identity
{
// FIXME(bgruber): we cannot remove this yet, because transform_iterator depends on it
using result_type _LIBCUDACXX_DEPRECATED_IN_CXX11 = T;
_CCCL_EXEC_CHECK_DISABLE
_CCCL_HOST_DEVICE constexpr const T& operator()(const T& x) const
{
return x;
}
_CCCL_EXEC_CHECK_DISABLE
_CCCL_HOST_DEVICE constexpr T& operator()(T& x) const
{
return x;
}
// we cannot add an overload for `const T&&` because then calling e.g. `thrust::identity<int>{}(3.14);` is ambiguous
// on MSVC
_CCCL_EXEC_CHECK_DISABLE
_CCCL_HOST_DEVICE constexpr T&& operator()(T&& x) const
{
return _CUDA_VSTD::move(x);
}
};
template <>
struct identity<void> : ::cuda::std::__identity
{};
using ::cuda::maximum;
using ::cuda::minimum;
template <typename T1 = void, typename T2 = void>
struct project1st
{
_CCCL_HOST_DEVICE constexpr const T1& operator()(const T1& lhs, const T2& /*rhs*/) const
{
return lhs;
}
};
template <>
struct project1st<void, void>
{
using is_transparent = void;
_CCCL_EXEC_CHECK_DISABLE
template <typename T1, typename T2>
_CCCL_HOST_DEVICE constexpr auto operator()(T1&& t1, T2&&) const noexcept(noexcept(THRUST_FWD(t1)))
-> decltype(THRUST_FWD(t1))
{
return THRUST_FWD(t1);
}
};
template <typename T1 = void, typename T2 = void>
struct project2nd
{
_CCCL_HOST_DEVICE constexpr const T2& operator()(const T1& /*lhs*/, const T2& rhs) const
{
return rhs;
}
}; // end project2nd
template <>
struct project2nd<void, void>
{
using is_transparent = void;
_CCCL_EXEC_CHECK_DISABLE
template <typename T1, typename T2>
_CCCL_HOST_DEVICE constexpr auto operator()(T1&&, T2&& t2) const noexcept(noexcept(THRUST_FWD(t2)))
-> decltype(THRUST_FWD(t2))
{
return THRUST_FWD(t2);
}
};
// odds and ends
using ::cuda::std::not_fn;
namespace placeholders
{
_CCCL_GLOBAL_CONSTANT thrust::detail::functional::placeholder<0>::type _1;
_CCCL_GLOBAL_CONSTANT thrust::detail::functional::placeholder<1>::type _2;
_CCCL_GLOBAL_CONSTANT thrust::detail::functional::placeholder<2>::type _3;
_CCCL_GLOBAL_CONSTANT thrust::detail::functional::placeholder<3>::type _4;
_CCCL_GLOBAL_CONSTANT thrust::detail::functional::placeholder<4>::type _5;
_CCCL_GLOBAL_CONSTANT thrust::detail::functional::placeholder<5>::type _6;
_CCCL_GLOBAL_CONSTANT thrust::detail::functional::placeholder<6>::type _7;
_CCCL_GLOBAL_CONSTANT thrust::detail::functional::placeholder<7>::type _8;
_CCCL_GLOBAL_CONSTANT thrust::detail::functional::placeholder<8>::type _9;
_CCCL_GLOBAL_CONSTANT thrust::detail::functional::placeholder<9>::type _10;
} // namespace placeholders
THRUST_NAMESPACE_END
#include <thrust/detail/functional/operators.h>
#include <thrust/detail/type_traits/is_commutative.h>