Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

copy assignable - what exactly is it?

218 views
Skip to first unread message

Doug Mika

unread,
Aug 10, 2015, 5:19:42 PM8/10/15
to
It says that the atomic bool is not copy-assignable, however, you can assign to it a bool value:

atomic<bool> b(true);
b=false; //assignment operation which relies on the overloaded copy assignment operator.

What is copy assignable and which operator does it rely on?

Bo Persson

unread,
Aug 10, 2015, 6:26:58 PM8/10/15
to
You are assigning a value, which is not a copy of an atomic variable.
Copy assign means assigning a value of the same type. Atomic types have
these operators deleted, to make them non-copyable.

atomic(const atomic&) = delete;
atomic& operator=(const atomic&) = delete;
atomic& operator=(const atomic&) volatile = delete;


Bo Persson

Doug Mika

unread,
Aug 10, 2015, 8:00:52 PM8/10/15
to
so which operator is used to assign a bool to an atomic, as in my case above?

Ian Collins

unread,
Aug 10, 2015, 9:14:35 PM8/10/15
to
atomic& operator=( T );

--
Ian Collins

Juha Nieminen

unread,
Aug 11, 2015, 4:10:43 AM8/11/15
to
"Copy-assignable" means that you can assign one instance to another. In other words:

std::atomic<bool> a(true), b(true);
a = b; // error

--- news://freenews.netfront.net/ - complaints: ne...@netfront.net ---

Vir Campestris

unread,
Aug 11, 2015, 4:49:45 PM8/11/15
to
On 11/08/2015 09:10, Juha Nieminen wrote:
> "Copy-assignable" means that you can assign one instance to another. In other words:
>
> std::atomic<bool> a(true), b(true);
> a = b; // error

Presumably a = static_cast<bool>(b); would work - extracting to a
non-atomic in the middle?

It would not of course be atomic...

Andy
0 new messages