@@ -43,8 +43,7 @@ struct resolve_concurrency_policy<First, Rest...> {
4343};
4444
4545template <policy::policy_type... Policies>
46- using resolve_concurrency_policy_t =
47- typename resolve_concurrency_policy<Policies...>::type;
46+ using resolve_concurrency_policy_t = resolve_concurrency_policy<Policies...>::type;
4847
4948} // namespace details
5049
@@ -58,50 +57,102 @@ public:
5857 " Multiple concurrency policies are not allowed" );
5958
6059 constexpr explicit primitive (value_type v) noexcept : value_(v) {}
60+
61+ constexpr primitive (primitive const &other) noexcept {
62+ if consteval {
63+ value_ = other.value_ ;
64+ } else {
65+ value_ = other.load ();
66+ }
67+ }
68+
69+ constexpr auto operator =(primitive const &other) noexcept -> primitive & {
70+ if (this == &other) {
71+ return *this ;
72+ }
73+
74+ if consteval {
75+ value_ = other.value_ ;
76+ } else {
77+ store (other.load ());
78+ }
79+ return *this ;
80+ }
81+
82+ constexpr primitive (primitive &&other) noexcept {
83+ if consteval {
84+ value_ = other.value_ ;
85+ } else {
86+ value_ = other.load ();
87+ }
88+ }
89+
90+ constexpr auto operator =(primitive &&other) noexcept -> primitive & {
91+ if (this == &other) {
92+ return *this ;
93+ }
94+
95+ if consteval {
96+ value_ = other.value_ ;
97+ } else {
98+ store (other.load ());
99+ }
100+ return *this ;
101+ }
102+
61103 constexpr value_type &value () noexcept { return value_; }
104+
62105 [[nodiscard]] constexpr value_type const &value () const noexcept {
63106 return value_;
64107 }
108+
65109 constexpr explicit operator value_type () const noexcept { return value_; }
66110
67- [[nodiscard]] auto load () const noexcept -> value_type {
68- using access_handler_t =
69- policy::concurrency::handler<concurrency_policy, void , value_type,
70- policy::error::kind>;
71- static_assert (
72- policy::concurrency::handler_access_available<concurrency_policy,
73- value_type>,
74- " Selected concurrency policy does not provide primitive "
75- " load/store/CAS support" );
111+ [[nodiscard]] constexpr auto load () const noexcept -> value_type {
112+ if consteval {
113+ return value_;
114+ }
115+ require_access_handler_ ();
76116 return access_handler_t::load (value_);
77117 }
78118
79- auto store (value_type desired) noexcept -> void {
80- using access_handler_t =
81- policy::concurrency::handler<concurrency_policy, void , value_type,
82- policy::error::kind>;
83- static_assert (
84- policy::concurrency::handler_access_available<concurrency_policy,
85- value_type>,
86- " Selected concurrency policy does not provide primitive "
87- " load/store/CAS support" );
88- access_handler_t::store (value_, desired);
119+ constexpr auto store (value_type desired) noexcept -> void {
120+ if consteval {
121+ value_ = desired;
122+ } else {
123+ require_access_handler_ ();
124+ access_handler_t::store (value_, desired);
125+ }
89126 }
90127
91- auto compare_exchange (value_type &expected, value_type desired) noexcept
92- -> bool {
93- using access_handler_t =
94- policy::concurrency::handler<concurrency_policy, void , value_type,
95- policy::error::kind>;
128+ constexpr auto compare_exchange (value_type &expected,
129+ value_type desired) noexcept -> bool {
130+ if consteval {
131+ if (value_ != expected) {
132+ expected = value_;
133+ return false ;
134+ }
135+
136+ value_ = desired;
137+ return true ;
138+ }
139+ require_access_handler_ ();
140+ return access_handler_t::compare_exchange (value_, expected, desired);
141+ }
142+
143+ private:
144+ using access_handler_t =
145+ policy::concurrency::handler<concurrency_policy, void , value_type,
146+ policy::error::kind>;
147+
148+ static constexpr auto require_access_handler_ () noexcept -> void {
96149 static_assert (
97150 policy::concurrency::handler_access_available<concurrency_policy,
98151 value_type>,
99152 " Selected concurrency policy does not provide primitive "
100153 " load/store/CAS support" );
101- return access_handler_t::compare_exchange (value_, expected, desired);
102154 }
103155
104- private:
105156 value_type value_;
106157};
107158
0 commit comments