I have say the following bool vector
v = [false ,true, false ,false ,true, false ,false ,true]
I want another vector which contains the indices of v for which the elements are true.
I have the following code:
std::vector<int> nds; //contains the indices
for (const auto &elem : v)
{
auto idx = &elem - &v[0];
if (elem)
{
nds.push_back(idx);
}
}
The above seems to work on my MacBook but it is causing the following error on Linux.
src/file.cpp:76:25: error: taking address of temporary [-fpermissive]
auto idx = &elem - &v[0];
^
Is there a better way to find the indices?
P.S. This is just a snippet of some larger code.