3#include <scl/feature/concepts/wrapper.h>
4#include <scl/feature/detail/executor_access.h>
6#include <scl/feature/type_traits/wrapper.h>
7#include <scl/utility/concepts/reference.h>
8#include <scl/utility/type_traits/forward_like.h>
14namespace scl::feature::detail
16 enum class wrapper_lock_case :
bool
22 template <::scl::concepts::reference Refer,
26 template <::scl::concepts::reference Refer>
27 class wrapper_lock<Refer, wrapper_lock_case::value>
30 wrapper_lock(wrapper_lock &&) =
delete;
31 wrapper_lock(wrapper_lock
const &) =
delete;
32 wrapper_lock & operator=(wrapper_lock &&) =
delete;
33 wrapper_lock & operator=(wrapper_lock
const &) =
delete;
34 ~wrapper_lock() =
default;
36 constexpr explicit wrapper_lock(Refer ref) noexcept
37 : m_ref{::std::forward<Refer>(ref)}
40 static constexpr void lock() noexcept {}
42 static constexpr void unlock() noexcept {}
45 constexpr Refer value() const noexcept
47 return ::std::forward<Refer>(m_ref);
54 template <concepts::wrapper_reference WrapperRefer>
55 class wrapper_lock<WrapperRefer, wrapper_lock_case::wrapper>
57 using wrapper_type = ::std::remove_cvref_t<WrapperRefer>;
58 using executor_type =
typename wrapper_type::executor_type;
59 using executor_refer = ::scl::forward_like_t<WrapperRefer, executor_type>;
60 using value_type =
typename wrapper_type::value_type;
61 using value_refer = ::scl::forward_like_t<WrapperRefer, value_type>;
64 wrapper_lock(wrapper_lock &&) =
delete;
65 wrapper_lock(wrapper_lock
const &) =
delete;
66 wrapper_lock & operator=(wrapper_lock &&) =
delete;
67 wrapper_lock & operator=(wrapper_lock
const &) =
delete;
69 constexpr explicit wrapper_lock(WrapperRefer ref) noexcept
70 : m_ref{::std::forward<WrapperRefer>(ref)}
73 constexpr ~wrapper_lock() noexcept(::scl::feature::
is_unguard_noexcept_v<executor_type, executor_refer>)
84 executor_type::guard(executor());
89 constexpr void unlock()
95 executor_type::unguard(executor());
101 constexpr bool locked() const noexcept
107 constexpr WrapperRefer wrapper_value() const noexcept
109 return ::std::forward<WrapperRefer>(m_ref);
113 constexpr value_refer value() const
114 noexcept(noexcept(executor_type::template access<executor_refer>(::std::declval<executor_refer>())))
116 executor_type::template access<executor_refer>(::std::declval<executor_refer>());
120 "wrapper_lock::value() requires the lock to be held for a guarding executor");
121 return executor_type::template access<executor_refer>(executor());
126 constexpr executor_refer executor() const noexcept
128 return executor_access::get(::std::forward<WrapperRefer>(m_ref));
132 bool m_locked{
false};
constexpr bool has_guard_v
true if ExecutorType has a guard() method whose first (and only) parameter type is exactly ExecutorRe...
Definition executor.h:93
constexpr bool has_unguard_v
true if ExecutorType has an unguard() method whose first (and only) parameter type is exactly Executo...
Definition executor.h:105
constexpr bool is_wrapper_v
Checks whether Type is a wrapper specialization.
Definition wrapper.h:32
constexpr bool is_unguard_noexcept_v
true if ExecutorType::unguard() for ExecutorRefer either does not exist or is noexcept.
Definition executor.h:194
constexpr bool is_guard_noexcept_v
true if ExecutorType::guard() for ExecutorRefer either does not exist or is noexcept.
Definition executor.h:182
Executor type traits: interface detection and noexcept helpers.