user1745995
user1745995

Reputation: 151

Is the a way to compare vector to be equal to part of another vector in C++?

If I have:

A = {"one", "two", "three"}

B = {"one", "two"}

I want to avoid creating a new vector from A. Is there a way to use [A.begin(), A.begin()+1] to compare with B?

Upvotes: 0

Views: 45

Answers (1)

Konrad Zapałowicz
Konrad Zapałowicz

Reputation: 281

There is a version of std::equal that could do:

template< class InputIt1, class InputIt2 >
bool equal( InputIt1 first1, InputIt1 last1,
            InputIt2 first2, InputIt2 last2 );

https://en.cppreference.com/w/cpp/algorithm/equal

Upvotes: 7

Related Questions