Hi:
The code doesn't compile here as std:bitset<bits> doesn't define the <
operator according to visual studio. I have a custom operator defined as
a structure:
struct BitSetComp
{
bool operator()(const std::bitset<6>& lhs, const std::bitset<6>&
rhs) const
{
return lhs.to_ulong() < rhs.to_ulong();
}
};
How can I use this in the code you providee, or do I need to redefine in
a certain way?
Cheers
Sean.
-----Original Message-----
From: boost-users-bounces@lists.boost.org
[mailto:boost-users-bounces@lists.boost.org] On Behalf Of Peter Barker
Sent: 09 September 2008 17:17
To: boost-users@lists.boost.org
Subject: Re: [Boost-users] Comparing two vectors element by element
On Tue, Sep 9, 2008 at 5:15 PM, Peter Barker
On Tue, Sep 9, 2008 at 4:55 PM, Sean Farrow
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 mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users __________ Information from ESET NOD32 Antivirus, version of virus signature database 3430 (20080910) __________ The message was checked by ESET NOD32 Antivirus. http://www.eset.com __________ Information from ESET NOD32 Antivirus, version of virus signature database 3430 (20080910) __________ The message was checked by ESET NOD32 Antivirus. http://www.eset.com