How to compare vector with array in efficient way in cpp?

I would like to write a code in a better (faster) way.
I have got a container vector and an simple array.
I would like to compare content of the vector with content of the array.
Suppose that I have got classes like this:

struct A
    float aa;
    struct(float p_aa) : aa(p_aa) {}

struct B : public A
    A bb;
    struct(float p_aa) : A(p_aa) {}

And I have also a container and an simple array:

std::vector<B> l_v = {B(1), B(3)};
B l_b[2] = {B(1), B(3)};

The function, which compare the container with the array is:

bool isTheSame(const std::vector<B> &l_v, B *l_b)
    unsigned int count = 0;
    for(auto it = l_v.begin(); it!= l_v.end(); ++it)
        if(l_b[count].aa != it->aa)
            return false;
    return true;

I would like to write it in a better way using lambda or foreach. Do you have any ideas? Thanks.

Source: c++

Leave a Reply