Boost logo

Boost Users :

Subject: Re: [Boost-users] Comparing two vectors element by element
From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2008-09-10 05:05:58


Hi!
This is not a directly a boost question. The answer is below

On Tue, Sep 9, 2008 at 5: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.
>

STL defines different algorithms in <algorithm> header. There is an equal
algorithm.

In you case you can write:

#include <vector>
#include <algorithm>
#include <functional>

using namespace std;
vector<int> v1;
vector<int> v2;

equal(v1.begin(), v1.end(), v2.begin(), less<int>());

This is how to compare 2 vector instances if one is less than the other. I
do not really understand your question about bitsets. Do you have vector of
bitsets? If so, replace int in vector template instantiation with your
bitset instantiation and less<int>() with the instance to your functor.

Hope that helps,
Ovanes



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