Improve the ergonomics of core.atomic

IGotD- nise at nise.com
Thu Oct 1 13:27:46 UTC 2020


Currently the core.atomic library just adds template functions 
for atomic operations and not a special atomic type. This forces 
the programmer to use long a rather ugly template operations 
through out the entire code.

Typically

atomicOp!"+="(v1, v2);

This is nice for casual atomic operations but ugly and a pain for 
many atomic operations.

Why hasn't D just like C++ an atomic type. In C++ you simply 
declare.

std::atomic<int> var;

and then use the operator overload.

var += 1;

which will trickle down to var.fetch_add(1);

This makes much nicer in the code. Also if you want swap between 
non atomic operations and atomic operations, you have to change 
less.

What D needs is just like in C++ an atomic template type.



More information about the Digitalmars-d mailing list