Boost logo

Boost Users :

Subject: Re: [Boost-users] Comparing two vectors element by element
From: Peter Barker (newbarker_at_[hidden])
Date: 2008-09-09 12:17:09


On Tue, Sep 9, 2008 at 5:15 PM, Peter Barker <newbarker_at_[hidden]> wrote:
> On Tue, Sep 9, 2008 at 4:55 PM, Sean Farrow
> <sean.farrow_at_[hidden]> wrote:
>> Hi:
>> I need to compare two vectors. I already have a function to compare two
>> individual elements (std::bitsets) in this case. Can I use boost.foreach
>> to do this, or is there a better way.
>> I need to know whether vector one, is less than vector two.
>>
>> Any help apreciated.
>> Cheers
>> Sean.
>
> Just use == as you do with built in data types e.g.:
>
> #include <vector>
> #include <iostream>
>
> int main()
> {
> std::vector<int> v1;
> std::vector<int> v2;
>
> if(v1 == v2)
> std::cout << "They're the same" << std::endl;
> }
>

Oops - sorry - I posted too quickly. Let's try again...

Just use the < operator as you would with built in types. e.g.:

#include <vector>
#include <iostream>

int main()
{
        std::vector<int> v1;
        v1.push_back(5);
        std::vector<int> v2;
        v2.push_back(6);

        if(v1 < v2)
                std::cout << "v1 is smaller than v2" << std::endl;
}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net