I have a class similar to this one:
struct orden
{
long long time;
double price;
const char* time1;
orden(const char* t, double p) : time1(t),price(p){};
void convertToMs()
{
time = dateToMs2(time1);
}
};
The what I'm doing is to read a file in serial, execute the constuctor of the struct and save the generated object in a vector of orden:
vector<orden> ord;
ifstream fe(filename)
while(getline(fe,order_line))
{
price = stod(order_line.substr(position+2));
time = order_line.substr(0,26).c_str();
ord.push_back(time, price);
}
Then, what I want to do in parallel is to execute the member function convertToMs(). But I have problems because the compiler ask me to execut only constant functions inside parallel for.
I have tryed some thinks that I have found like this one Without sucess because they are not saving the result of the execution in a parameter of the object.
What I'm doing wrong?
Thank you in advance
EDIT:
If I use
struct orden
{
long long time;
double price;
const char* time1;
orden(const char* t, double p) : time1(t),price(p){};
void convertToMs() const
{
time = dateToMs2(time1);
}
};
I have the following error:
In file included from pract1.cpp:5:0:
orden.h: In member function ‘void orden::convertToMs() const’:
orden.h:29:27: error: assignment of member ‘orden::time’ in read-only object
time = dateToMs2(time1);
If I delete the const i have the following one:
pract1.cpp: In lambda function:
pract1.cpp:158:43: error: passing ‘const value_type {aka const orden}’ as ‘this’ argument discards qualifiers [-fpermissive]
ordersOfTheCompany[j].convertToMs();
^
In file included from pract1.cpp:5:0:
orden.h:27:8: note: in call to ‘void orden::convertToMs()’
void convertToMs()
EDIT 2:
Sorry again, i have the folloging code:
vector<orden> ord;
while(getline(fe,order_line))
{
price = stod(order_line.substr(position+2));
time = order_line.substr(0,26).c_str();
ord.push_back(time, price);
}
tbb::parallel_for(tbb::blocked_range<size_t>(0,ord.size()),
[=](tbb::blocked_range<size_t>& r) {
for(std::size_t j=r.begin(); j!=r.end(); ++j)
{
ord[j].convertToMs();
}});
I'm trying to execute the member function in a parallel for