Skip to content

Commit

Permalink
Deprecate thrust::optional
Browse files Browse the repository at this point in the history
Fixes: #3306
  • Loading branch information
bernhardmgruber committed Jan 9, 2025
1 parent f43dc54 commit e7b8e50
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
18 changes: 12 additions & 6 deletions thrust/thrust/optional.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include <type_traits>
#include <utility>

_CCCL_SUPPRESS_DEPRECATED_PUSH

#if _CCCL_COMPILER(MSVC, ==, 19, 00)
# define THRUST_OPTIONAL_MSVC2015
#endif
Expand All @@ -59,11 +61,10 @@ THRUST_NAMESPACE_BEGIN
#ifndef THRUST_MONOSTATE_INPLACE_MUTEX
# define THRUST_MONOSTATE_INPLACE_MUTEX
/// \brief Used to represent an optional with no data; essentially a bool
class monostate
{};
class CCCL_DEPRECATED monostate{};

/// \brief A tag type to tell optional to construct its value in-place
struct in_place_t
struct CCCL_DEPRECATED in_place_t
{
explicit in_place_t() = default;
};
Expand All @@ -72,7 +73,7 @@ static constexpr in_place_t in_place{};
#endif

template <class T>
class optional;
class CCCL_DEPRECATED_BECAUSE("Use cuda::std::optional") optional;

/// \exclude
namespace detail
Expand Down Expand Up @@ -722,7 +723,7 @@ struct optional_delete_assign_base<T, false, false>
} // namespace detail

/// \brief A tag type to represent an empty optional
struct nullopt_t
struct CCCL_DEPRECATED nullopt_t
{
struct do_not_use
{};
Expand All @@ -744,7 +745,7 @@ static constexpr
#endif // __CUDA_ARCH__
nullopt_t nullopt{nullopt_t::do_not_use{}, nullopt_t::do_not_use{}};

class bad_optional_access : public std::exception
class CCCL_DEPRECATED bad_optional_access : public std::exception
{
public:
bad_optional_access() = default;
Expand Down Expand Up @@ -1954,19 +1955,22 @@ _CCCL_EXEC_CHECK_DISABLE
template <class T = detail::i_am_secret,
class U,
class Ret = detail::conditional_t<std::is_same<T, detail::i_am_secret>::value, detail::decay_t<U>, T>>
CCCL_DEPRECATED_BECAUSE("Use cuda::std::make_optional")
_CCCL_HOST_DEVICE inline constexpr optional<Ret> make_optional(U&& v)
{
return optional<Ret>(std::forward<U>(v));
}

_CCCL_EXEC_CHECK_DISABLE
template <class T, class... Args>
CCCL_DEPRECATED_BECAUSE("Use cuda::std::make_optional")
_CCCL_HOST_DEVICE inline constexpr optional<T> make_optional(Args&&... args)
{
return optional<T>(in_place, std::forward<Args>(args)...);
}
_CCCL_EXEC_CHECK_DISABLE
template <class T, class U, class... Args>
CCCL_DEPRECATED_BECAUSE("Use cuda::std::make_optional")
_CCCL_HOST_DEVICE inline constexpr optional<T> make_optional(std::initializer_list<U> il, Args&&... args)
{
return optional<T>(in_place, il, std::forward<Args>(args)...);
Expand Down Expand Up @@ -2822,3 +2826,5 @@ struct hash<THRUST_NS_QUALIFIER::optional<T>>
}
};
} // namespace std

_CCCL_SUPPRESS_DEPRECATED_POP
27 changes: 19 additions & 8 deletions thrust/thrust/system/cuda/detail/future.inl
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,9 @@ struct unique_eager_future_promise_pair final
weak_promise<X, XPointer> promise;
};

struct acquired_stream final
_CCCL_SUPPRESS_DEPRECATED_PUSH // for thrust::optional

struct acquired_stream final
{
unique_stream stream;
optional<std::size_t> const acquired_from;
Expand Down Expand Up @@ -340,6 +342,8 @@ inline _CCCL_HOST optional<unique_stream> try_acquire_stream(int device, unique_
template <typename X>
_CCCL_HOST optional<unique_stream> try_acquire_stream(int device, unique_eager_future<X>& parent) noexcept;

_CCCL_SUPPRESS_DEPRECATED_POP

template <typename... Dependencies>
_CCCL_HOST acquired_stream acquire_stream(int device, Dependencies&... deps) noexcept;

Expand Down Expand Up @@ -743,8 +747,10 @@ public:
stream().wait();
}

friend _CCCL_HOST optional<detail::unique_stream>
thrust::system::cuda::detail::try_acquire_stream(int device_id, unique_eager_event& parent) noexcept;
_CCCL_SUPPRESS_DEPRECATED_PUSH // for thrust::optional
friend _CCCL_HOST optional<detail::unique_stream>
thrust::system::cuda::detail::try_acquire_stream(int device_id, unique_eager_event& parent) noexcept;
_CCCL_SUPPRESS_DEPRECATED_POP

template <typename... Dependencies>
friend _CCCL_HOST unique_eager_event
Expand Down Expand Up @@ -901,9 +907,11 @@ public:
}
# endif

template <typename X>
friend _CCCL_HOST optional<detail::unique_stream>
thrust::system::cuda::detail::try_acquire_stream(int device_id, unique_eager_future<X>& parent) noexcept;
_CCCL_SUPPRESS_DEPRECATED_PUSH // for thrust::optional
template <typename X>
friend _CCCL_HOST optional<detail::unique_stream>
thrust::system::cuda::detail::try_acquire_stream(int device_id, unique_eager_future<X>& parent) noexcept;
_CCCL_SUPPRESS_DEPRECATED_POP

template <typename X, typename XPointer, typename ComputeContent, typename... Dependencies>
friend _CCCL_HOST detail::unique_eager_future_promise_pair<X, XPointer>
Expand All @@ -916,9 +924,10 @@ public:

namespace detail
{
_CCCL_SUPPRESS_DEPRECATED_PUSH // for thrust::optional

template <typename X, typename Deleter>
_CCCL_HOST optional<unique_stream> try_acquire_stream(int, std::unique_ptr<X, Deleter>&) noexcept
template <typename X, typename Deleter>
_CCCL_HOST optional<unique_stream> try_acquire_stream(int, std::unique_ptr<X, Deleter>&) noexcept
{
// There's no stream to acquire!
return {};
Expand Down Expand Up @@ -973,6 +982,8 @@ _CCCL_HOST optional<unique_stream> try_acquire_stream(int device_id, unique_eage
return {};
}

_CCCL_SUPPRESS_DEPRECATED_POP

///////////////////////////////////////////////////////////////////////////////

template <typename... Dependencies>
Expand Down

0 comments on commit e7b8e50

Please sign in to comment.