How can I assign the members of a vector with an atomic type?
#include <iostream>
#include <thread>
#include <vector>
using namespace std;
int main()
{
vector<atomic<bool>> myvector;
int N=8;
myvector.assign(N,false);
cout<<"done!"<<endl;
}
https://wandbox.org/permlink/lchfOvqyL3YKNivk
prog.cc: In function 'int main()':
prog.cc:11:28: error: no matching function for call to 'std::vector<std::atomic<bool> >::assign(int&, bool)'
11 | myvector.assign(N,false);
| ^
Atomic vectors are linear vectors of a single primitive type, like an STL Vector in C++. There is no useful literal syntax for this fundamental data type. To create one of these stupid beasts, assign like:
An atomic vector is different from a one-dimensional array because it has a dim attribute of length while a vector has no such attribute. Atomic vector is also different from the list since the vector items have the same types, while a list can contain various arbitrary data types. There are five types of atomic vectors.
Atomic data types are the object types that you can use to create atomic vectors. To check if any data object is atomic in R, use the is.atomic () function. Atomic vector is a fundamental data structure in the R programming language.
To check if any data object is atomic in R, use the is.atomic () function. Atomic vector is a fundamental data structure in the R programming language. An atomic vector is different from a one-dimensional array because it has a dim attribute of length while a vector has no such attribute.
std::atomic
is neither copyable or move constructible, so you might do instead:
std::vector<std::atomic<bool>> myvector(8);
for (auto& b : myvector) { std::atomic_init(&b, false); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With