Hi All,
I am encountering issue whereby my function enters an infinite loop in the below example.
Code:
Function a{
:
const sparse_data& sparse = ra_data->sparse(x, y, site, colum);
for(sparse_data::const_iterator si = sparse.begin(); si != sparse.end();) {
// Invoked some function B that alters the content of sdata->sparse
// Does si++ in the for loop
}
:
}
I tried removing the referencing and this actually solved my problem.
Code:
Function a {
:
const sparse_data sparse = sdata->sparse(x, y, site, column);
for(sparse_data::const_iterator si = sparse.begin(); si != sparse.end();) {
// Invoked some function B that alters the content of sdata->sparse
// Does si++ in the for loop
}
:
}
I was hoping someone can guide me on why does this happen.
My guess on the issue is that the function B inside the for loop changes the sparse since it is a reference to sdata->sparse. Hence when the for loop checks the end condition, si = sparse.end is no longer valid fulfiled.
Apologies for the lack of actual coding as they are proprietary information of my company.