0

I have code like that:

for (size_t i = 0; i < m_particleVertex.size(); i++)
{
    auto actualPosition = m_particleVertex()[i].position;
    ...
    m_particleAttributes[i].setDirection(newDirection);
}

And I wonder if it okay to use STL here? I want to try to do this with some modern c++. Range for loop is not an option because of different types of m_particleVertex and m_particleAttributes. So yeah... i'm thinking of use for_each function, but i don't know if it is possible without any additional containers. I wrote this:

std::for_each(m_particleAttributes.begin(), m_particleAttributes.end(), [&](ParticleSettings& particleAttribute, sf::Vertex& particleVertex) mutable {
    auto actualPosition = particleVertex.position;
    ...
    particleAttribute.setDirection(newDirection);
    });

and i know that i cannot do this, so i'm thinking that i should do something like that:

std::vector<vector2f> temp;
std::for_each(m_particleAttributes.begin(), m_particleAttributes.end(), [&](ParticleSettings& particleAttribute) mutable { temp.push_back(particleVertex.position);}

and than do operations for every element of vector, and do the same for particleAttribute.setDirection() method. I don't know if it is proper idea, efficient idea, and if there is something better to use? Any ideas? What are you thinking? Is it okay to use here STL or not?

Tojmak
  • 155
  • 1
  • 7
  • 1
    Related [question](https://stackoverflow.com/questions/12552277/whats-the-best-way-to-iterate-over-two-or-more-containers-simultaneously). – cigien Apr 23 '20 at 17:47
  • zip view (from [range-v3](https://github.com/ericniebler/range-v3) (not in [C++20 ranges](https://en.cppreference.com/w/cpp/ranges) :-/ )) would be my preferred way. – Jarod42 Apr 23 '20 at 18:17
  • Thanks, i will look at that ideas. C++20 ranges sounds interesting – Tojmak Apr 23 '20 at 19:51
  • Is there any option without additional libraries? – Tojmak Apr 24 '20 at 08:13

0 Answers0