473,394 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

using a std::bitset in an iterator

Hi:
I have an iterator defined as follows:
std::map<std::bitset<6>, int>::iterator DotsIterator, SignsIterator;

I get errors that std::bitset does not declare the < operator. Does this
mean I can not use std::bitset in an iterator. Any help apreciated.

Cheers

Sean.
Aug 24 '08 #1
5 5568
Sean Farrow wrote:
Hi:
I have an iterator defined as follows:
std::map<std::bitset<6>, int>::iterator DotsIterator, SignsIterator;

I get errors that std::bitset does not declare the < operator. Does this
mean I can not use std::bitset in an iterator. Any help apreciated.
You have to specify a comparison operator for the map to use. For
example like this:

typedef std::bitset<6KeyType;

struct BitSetComp
{
bool operator()(const KeyType& lhs, const KeyType& rhs)
{
return lhs.to_ulong() < rhs.to_ulong();
}
};

int main()
{
typedef std::map<KeyType, int, BitSetCompBitSetMap;
BitSetMap m;
BitSetMap::iterator iter = m.begin();
}
Aug 24 '08 #2
On 2008-08-24 18:38:52 -0400, "Sean Farrow"
<se*********@seanfarrow.co.uksaid:
I have an iterator defined as follows:
std::map<std::bitset<6>, int>::iterator DotsIterator, SignsIterator;

I get errors that std::bitset does not declare the < operator. Does this
mean I can not use std::bitset in an iterator. Any help apreciated.
It means you can't use it in a map. Other containers don't require ordering.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Aug 25 '08 #3
On 25 Aug, 01:04, Juha Nieminen <nos...@thanks.invalidwrote:
* You have to specify a comparison operator for the map to use. For
example like this:

typedef std::bitset<6KeyType;

struct BitSetComp
{
* * bool operator()(const KeyType& lhs, const KeyType& rhs)
* * {
* * * * return lhs.to_ulong() < rhs.to_ulong();
* * }

};
nit: the operator must be const, otherwise the predicate can't be used
with map
int main()
{
* * typedef std::map<KeyType, int, BitSetCompBitSetMap;
* * BitSetMap m;
* * BitSetMap::iterator iter = m.begin();
}
DP
Aug 25 '08 #4
Hi:
Thanks to all. I've now solved the issues.
Sean.
"Pete Becker" <pe**@versatilecoding.comwrote in message
news:2008082422581116807-pete@versatilecodingcom...
On 2008-08-24 18:38:52 -0400, "Sean Farrow" <se*********@seanfarrow.co.uk>
said:
>I have an iterator defined as follows:
std::map<std::bitset<6>, int>::iterator DotsIterator, SignsIterator;

I get errors that std::bitset does not declare the < operator. Does this
mean I can not use std::bitset in an iterator. Any help apreciated.

It means you can't use it in a map. Other containers don't require
ordering.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Aug 25 '08 #5
Hi:
When executing the following line:
DotsIterator =DotsList.find(dots);

I get the following error:

C2679: binary '=' : no operator found which takes a right-hand operand of
type 'std::_Tree<_Traits>::iterator' (or there . I
is no acceptable conversion)

DotsIterator is defined as:

std::map<std::bitset<6>, int>::iterator DotsIterator;

How can I solve this issue. I'm using visual c++ 2005.

Cheers

Sean.

"Sean Farrow" <se*********@seanfarrow.co.ukwrote in message
news:48***********************@news.zen.co.uk...
Hi:
Thanks to all. I've now solved the issues.
Sean.
"Pete Becker" <pe**@versatilecoding.comwrote in message
news:2008082422581116807-pete@versatilecodingcom...
>On 2008-08-24 18:38:52 -0400, "Sean Farrow"
<se*********@seanfarrow.co.uksaid:
>>I have an iterator defined as follows:
std::map<std::bitset<6>, int>::iterator DotsIterator, SignsIterator;

I get errors that std::bitset does not declare the < operator. Does this
mean I can not use std::bitset in an iterator. Any help apreciated.

It means you can't use it in a map. Other containers don't require
ordering.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)


Aug 25 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dill Hole | last post by:
Can anyone tell me why std::bitset<2> foo(std::string("01")) initializes the bitset in reverse order, i.e. foo=true foo=false I would expect the bitset to be initialized in string text...
5
by: SpOiLeR | last post by:
Hi. q1: Is std::bitset<N> part of standard or it's compiler extension? q2: Is std::bitset::to_string() part of standard? q3: My documentation say this about std::bitset::to_string(): ...
3
by: Gaijinco | last post by:
In C++ this code: for(int i=0; i<16; ++i){ std::cout << std::bitset<4>(i) << std::endl; Will print numbers 1-15 as binaries with 4 bits. Is there any equivalent of bitset in C?
14
by: Haro Panosyan | last post by:
How to construct a bitset from string? For example: std::bitset<16> b16("1011011110001011"); Is this possible? Thanks in advance. -haro
7
by: felixnielsen | last post by:
I would wery much like this to work: @code start #include <iostream> #include <bitset> const unsigned short size = 2; // 2^<unsigned int> // union V { char c; std::bitset<size*size*size> b;...
7
by: Donos | last post by:
Hello I have a Queue which is declared as, std::queue<unsigned charm_Queue; I push data into this queue. Now i want to take the data out of this queue using Iterator.
2
by: mathieu | last post by:
Hi there, I must be doing something wrong, but I do not understand the documentation for bitset( string ), shouldn't this be equivalent (ref == mask ) ? #include <bitset> #include...
3
by: Guy.Tristram | last post by:
Is there any good reason operator< is not defined for std::bitset? It seems to me that: 1 - it would be useful. 2 - it is easy to implement inside the class template. 3 - it is impossible to...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.