MCPcopy Create free account
hub / github.com/cameron314/concurrentqueue / ThrowingMovable

Class ThrowingMovable

tests/unittests/unittests.cpp:214–284  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

212};
213
214struct ThrowingMovable {
215 static std::atomic<int>& ctorCount() { static std::atomic<int> c; return c; }
216 static std::atomic<int>& destroyCount() { static std::atomic<int> c; return c; }
217 static void reset() { ctorCount() = 0; destroyCount() = 0; }
218
219 explicit ThrowingMovable(int id, bool throwOnCctor = false, bool throwOnAssignment = false, bool throwOnSecondCctor = false)
220 : id(id), moved(false), copied(false), throwOnCctor(throwOnCctor), throwOnAssignment(throwOnAssignment), throwOnSecondCctor(throwOnSecondCctor)
221 {
222 ctorCount().fetch_add(1, std::memory_order_relaxed);
223 }
224
225 ThrowingMovable(ThrowingMovable const& o)
226 : id(o.id), moved(false), copied(true), throwOnCctor(o.throwOnCctor), throwOnAssignment(o.throwOnAssignment), throwOnSecondCctor(false)
227 {
228 if (throwOnCctor) {
229 throw this;
230 }
231 ctorCount().fetch_add(1, std::memory_order_relaxed);
232 throwOnCctor = o.throwOnSecondCctor;
233 }
234
235 ThrowingMovable(ThrowingMovable&& o)
236 : id(o.id), moved(true), copied(false), throwOnCctor(o.throwOnCctor), throwOnAssignment(o.throwOnAssignment), throwOnSecondCctor(false)
237 {
238 if (throwOnCctor) {
239 throw this;
240 }
241 ctorCount().fetch_add(1, std::memory_order_relaxed);
242 throwOnCctor = o.throwOnSecondCctor;
243 }
244
245 ~ThrowingMovable()
246 {
247 destroyCount().fetch_add(1, std::memory_order_relaxed);
248 }
249
250 void operator=(ThrowingMovable const& o)
251 {
252 id = o.id;
253 moved = false;
254 copied = true;
255 throwOnCctor = o.throwOnCctor;
256 throwOnAssignment = o.throwOnAssignment;
257 throwOnSecondCctor = o.throwOnSecondCctor;
258 if (throwOnAssignment) {
259 throw this;
260 }
261 }
262
263 void operator=(ThrowingMovable&& o)
264 {
265 id = o.id;
266 moved = true;
267 copied = false;
268 throwOnCctor = o.throwOnCctor;
269 throwOnAssignment = o.throwOnAssignment;
270 throwOnSecondCctor = o.throwOnSecondCctor;
271 if (throwOnAssignment) {

Callers 1

exceptionsMethod · 0.85

Calls

no outgoing calls

Tested by 1

exceptionsMethod · 0.68