473,513 Members | 2,448 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

error with tr1 unordered_map iterator

Hi,

I am using tr1/unordered_map in my code.

My code compiled ok on g++ (GCC) 4.1.2 (Ubuntu 4.1.2-0ubuntu1). Now I
need to compile my code on g++ (GCC) 4.0.3 (Ubuntu 4.0.3-1ubuntu5).

I get a messy error. Here are what I try to do:

typedef unordered_map<string, unsignedStringHash;
....
StringHash::const_iterator word_pos;

I get the error when I create the const_iterator:

index.cc:161: error: no matching function for call to
‘Internal::hashtable_iterator<std::pair<const std::basic_string<char,
std::char_traits<char>, std::allocator<char, unsigned int>, true,
false>::hashtable_iterator()’

Removing const from the iterator does not make any difference.

I tried to add const to string:

typedef unordered_map<const string, unsignedStringHash;
....
typedef set<unsignedWordLevelEntrySet;
typedef pair<StringHash::const_iterator, WordLevelEntrySetWordLevelEntry;

And the error moves to another place but is also on const_iterator:

/usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/tr1/hashtable:
In instantiation of ‘Internal::hash_code_base<const
std::basic_string<char, std::char_traits<char>, std::allocator<char,
std::pair<const std::basic_string<char, std::char_traits<char>,
std::allocator<char, unsigned int>,
Internal::extract1st<std::pair<const std::basic_string<char,
std::char_traits<char>, std::allocator<char, unsigned int,
std::equal_to<const std::basic_string<char, std::char_traits<char>,
std::allocator<char >, std::tr1::hash<const std::basic_string<char,
std::char_traits<char>, std::allocator<char >,
Internal::mod_range_hashing, Internal::default_ranged_hash, false>’:

Is probably something that has been fixed or improved between the
versions. Is there any workaround?

Thanks a lot,
Ray
Feb 24 '07 #1
6 8578
Rares Vernica wrote:
Hi,

I am using tr1/unordered_map in my code.

My code compiled ok on g++ (GCC) 4.1.2 (Ubuntu 4.1.2-0ubuntu1). Now I
need to compile my code on g++ (GCC) 4.0.3 (Ubuntu 4.0.3-1ubuntu5).

I get a messy error. Here are what I try to do:

typedef unordered_map<string, unsignedStringHash;
...
StringHash::const_iterator word_pos;

I get the error when I create the const_iterator:

index.cc:161: error: no matching function for call to
‘Internal::hashtable_iterator<std::pair<const std::basic_string<char,
std::char_traits<char>, std::allocator<char, unsigned int>, true,
false>::hashtable_iterator()’

Removing const from the iterator does not make any difference.

I tried to add const to string:

typedef unordered_map<const string, unsignedStringHash;
...
typedef set<unsignedWordLevelEntrySet;
typedef pair<StringHash::const_iterator, WordLevelEntrySetWordLevelEntry;

And the error moves to another place but is also on const_iterator:

/usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/tr1/hashtable:
In instantiation of ‘Internal::hash_code_base<const
std::basic_string<char, std::char_traits<char>, std::allocator<char,
std::pair<const std::basic_string<char, std::char_traits<char>,
std::allocator<char, unsigned int>,
Internal::extract1st<std::pair<const std::basic_string<char,
std::char_traits<char>, std::allocator<char, unsigned int,
std::equal_to<const std::basic_string<char, std::char_traits<char>,
std::allocator<char >, std::tr1::hash<const std::basic_string<char,
std::char_traits<char>, std::allocator<char >,
Internal::mod_range_hashing, Internal::default_ranged_hash, false>’:

Is probably something that has been fixed or improved between the
versions. Is there any workaround?

Thanks a lot,
Ray
I will need to check if I have the tr1 headers and see if I can
duplicate your errors since I am locked down on 4.0.1. It would
really suck if I cannot use them either. I'll get back to you on
this on Monday if you can wait :) BTW, do you know if G++ people
already puts the tr1 headers in the 4.0.1 dist?

As a workaround you can use ext/hash_map that the G++ folks provide.
Since it is not a widely accepted norm they namespaced it which
makes your code less portable :)

HTH
Feb 25 '07 #2
Rares Vernica wrote:
Hi,

I am using tr1/unordered_map in my code.

My code compiled ok on g++ (GCC) 4.1.2 (Ubuntu 4.1.2-0ubuntu1). Now I
need to compile my code on g++ (GCC) 4.0.3 (Ubuntu 4.0.3-1ubuntu5).

I get a messy error. Here are what I try to do:

typedef unordered_map<string, unsignedStringHash;
...
StringHash::const_iterator word_pos;

I get the error when I create the const_iterator:

index.cc:161: error: no matching function for call to
‘Internal::hashtable_iterator<std::pair<const std::basic_string<char,
std::char_traits<char>, std::allocator<char, unsigned int>, true,
false>::hashtable_iterator()’

Removing const from the iterator does not make any difference.

I tried to add const to string:

typedef unordered_map<const string, unsignedStringHash;
...
typedef set<unsignedWordLevelEntrySet;
typedef pair<StringHash::const_iterator, WordLevelEntrySetWordLevelEntry;

And the error moves to another place but is also on const_iterator:

/usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/tr1/hashtable:
In instantiation of ‘Internal::hash_code_base<const
std::basic_string<char, std::char_traits<char>, std::allocator<char,
std::pair<const std::basic_string<char, std::char_traits<char>,
std::allocator<char, unsigned int>,
Internal::extract1st<std::pair<const std::basic_string<char,
std::char_traits<char>, std::allocator<char, unsigned int,
std::equal_to<const std::basic_string<char, std::char_traits<char>,
std::allocator<char >, std::tr1::hash<const std::basic_string<char,
std::char_traits<char>, std::allocator<char >,
Internal::mod_range_hashing, Internal::default_ranged_hash, false>’:

Is probably something that has been fixed or improved between the
versions. Is there any workaround?

Thanks a lot,
Ray
Woah this is way odd but based on my tests,
unordered_map::iterator has no default constructor.
This is what you seem to be encountering. I am not
sure if that is a bug on G++'s part or not or if
TR1 specifies that it need not be default constructible.
--------------------------------------------------------
#include <tr1/unordered_map>
#include <string>

using namespace std;
using namespace std::tr1;
typedef unordered_map<string, unsignedStringHash;

int
main()
{
StringHash myHashTable;
// assume you added some stuff in it

StringHash::const_iterator iter( myHashTable.begin() );

}
Feb 27 '07 #3
Piyo wrote:
Rares Vernica wrote:
>Hi,

I am using tr1/unordered_map in my code.

My code compiled ok on g++ (GCC) 4.1.2 (Ubuntu 4.1.2-0ubuntu1). Now I
need to compile my code on g++ (GCC) 4.0.3 (Ubuntu 4.0.3-1ubuntu5).

I get a messy error. Here are what I try to do:

typedef unordered_map<string, unsignedStringHash;
...
StringHash::const_iterator word_pos;

I get the error when I create the const_iterator:

index.cc:161: error: no matching function for call to
‘Internal::hashtable_iterator<std::pair<const std::basic_string<char,
std::char_traits<char>, std::allocator<char, unsigned int>, true,
false>::hashtable_iterator()’

Removing const from the iterator does not make any difference.

I tried to add const to string:

typedef unordered_map<const string, unsignedStringHash;
...
typedef set<unsignedWordLevelEntrySet;
typedef pair<StringHash::const_iterator, WordLevelEntrySet>
WordLevelEntry;

And the error moves to another place but is also on const_iterator:

/usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/tr1/hashtable:
In instantiation of ‘Internal::hash_code_base<const
std::basic_string<char, std::char_traits<char>, std::allocator<char>
>, std::pair<const std::basic_string<char, std::char_traits<char>,
std::allocator<char, unsigned int>,
Internal::extract1st<std::pair<const std::basic_string<char,
std::char_traits<char>, std::allocator<char, unsigned int,
std::equal_to<const std::basic_string<char, std::char_traits<char>,
std::allocator<char >, std::tr1::hash<const std::basic_string<char,
std::char_traits<char>, std::allocator<char >,
Internal::mod_range_hashing, Internal::default_ranged_hash, false>’:

Is probably something that has been fixed or improved between the
versions. Is there any workaround?

Thanks a lot,
Ray

Woah this is way odd but based on my tests,
unordered_map::iterator has no default constructor.
This is what you seem to be encountering. I am not
sure if that is a bug on G++'s part or not or if
TR1 specifies that it need not be default constructible.
--------------------------------------------------------
#include <tr1/unordered_map>
#include <string>

using namespace std;
using namespace std::tr1;
typedef unordered_map<string, unsignedStringHash;

int
main()
{
StringHash myHashTable;
// assume you added some stuff in it

StringHash::const_iterator iter( myHashTable.begin() );

}
Yes, it seems that the iterator does not have a default constructor.

I hope I am wrong. :)

Thanks,
Ray

Feb 27 '07 #4
On 28 fév, 00:07, Rares Vernica <rvern...@gmail.comwrote:
Piyo wrote:
Rares Vernica wrote:
Hi,
I am using tr1/unordered_map in my code.
My code compiled ok on g++ (GCC) 4.1.2 (Ubuntu 4.1.2-0ubuntu1). Now I
need to compile my code on g++ (GCC) 4.0.3 (Ubuntu 4.0.3-1ubuntu5).
I get a messy error. Here are what I try to do:
typedef unordered_map<string, unsignedStringHash;
...
StringHash::const_iterator word_pos;
I get the error when I create the const_iterator:
index.cc:161: error: no matching function for call to
'Internal::hashtable_iterator<std::pair<const std::basic_string<char,
std::char_traits<char>, std::allocator<char, unsigned int>, true,
false>::hashtable_iterator()'
Removing const from the iterator does not make any difference.
I tried to add const to string:
typedef unordered_map<const string, unsignedStringHash;
...
typedef set<unsignedWordLevelEntrySet;
typedef pair<StringHash::const_iterator, WordLevelEntrySet>
WordLevelEntry;
And the error moves to another place but is also on const_iterator:
/usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/tr1/hashtable:
In instantiation of 'Internal::hash_code_base<const
std::basic_string<char, std::char_traits<char>, std::allocator<char>
, std::pair<const std::basic_string<char, std::char_traits<char>,
std::allocator<char, unsigned int>,
Internal::extract1st<std::pair<const std::basic_string<char,
std::char_traits<char>, std::allocator<char, unsigned int,
std::equal_to<const std::basic_string<char, std::char_traits<char>,
std::allocator<char >, std::tr1::hash<const std::basic_string<char,
std::char_traits<char>, std::allocator<char >,
Internal::mod_range_hashing, Internal::default_ranged_hash, false>':
Is probably something that has been fixed or improved between the
versions. Is there any workaround?
Thanks a lot,
Ray
Woah this is way odd but based on my tests,
unordered_map::iterator has no default constructor.
This is what you seem to be encountering. I am not
sure if that is a bug on G++'s part or not or if
TR1 specifies that it need not be default constructible.
--------------------------------------------------------
#include <tr1/unordered_map>
#include <string>
using namespace std;
using namespace std::tr1;
typedef unordered_map<string, unsignedStringHash;
int
main()
{
StringHash myHashTable;
// assume you added some stuff in it
StringHash::const_iterator iter( myHashTable.begin() );
}

Yes, it seems that the iterator does not have a default constructor.

I hope I am wrong. :)

Thanks,
Ray
The TR1 only states that the unordered_map iterators are "of at least
the forward iterator category", so I guess they have to respect the
standard requirements (which in this case means that they should have
a default constructor, as per table 74 (§24.1.3)). I'd consider this
to be a bug in the TR1 implementation that comes with g++ (but that's
not like this implementation was complete) - unless I misundertood
something.

Regards,

-- Emmanuel Deloget

Feb 28 '07 #5
Emmanuel Deloget wrote:
On 28 fév, 00:07, Rares Vernica <rvern...@gmail.comwrote:
>Piyo wrote:
>>Rares Vernica wrote:
Hi,
I am using tr1/unordered_map in my code.
My code compiled ok on g++ (GCC) 4.1.2 (Ubuntu 4.1.2-0ubuntu1). Now I
need to compile my code on g++ (GCC) 4.0.3 (Ubuntu 4.0.3-1ubuntu5).
I get a messy error. Here are what I try to do:
typedef unordered_map<string, unsignedStringHash;
...
StringHash::const_iterator word_pos;
I get the error when I create the const_iterator:
index.cc:161: error: no matching function for call to
'Internal::hashtable_iterator<std::pair<const std::basic_string<char,
std::char_traits<char>, std::allocator<char, unsigned int>, true,
false>::hashtable_iterator()'
Removing const from the iterator does not make any difference.
I tried to add const to string:
typedef unordered_map<const string, unsignedStringHash;
...
typedef set<unsignedWordLevelEntrySet;
typedef pair<StringHash::const_iterator, WordLevelEntrySet>
WordLevelEntry;
And the error moves to another place but is also on const_iterator:
/usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/tr1/hashtable:
In instantiation of 'Internal::hash_code_base<const
std::basic_string<char, std::char_traits<char>, std::allocator<char>
, std::pair<const std::basic_string<char, std::char_traits<char>,
std::allocator<char, unsigned int>,
Internal::extract1st<std::pair<const std::basic_string<char,
std::char_traits<char>, std::allocator<char, unsigned int,
std::equal_to<const std::basic_string<char, std::char_traits<char>,
std::allocator<char >, std::tr1::hash<const std::basic_string<char,
std::char_traits<char>, std::allocator<char >,
Internal::mod_range_hashing, Internal::default_ranged_hash, false>':
Is probably something that has been fixed or improved between the
versions. Is there any workaround?
Thanks a lot,
Ray
Woah this is way odd but based on my tests,
unordered_map::iterator has no default constructor.
This is what you seem to be encountering. I am not
sure if that is a bug on G++'s part or not or if
TR1 specifies that it need not be default constructible.
--------------------------------------------------------
#include <tr1/unordered_map>
#include <string>
using namespace std;
using namespace std::tr1;
typedef unordered_map<string, unsignedStringHash;
int
main()
{
StringHash myHashTable;
// assume you added some stuff in it
StringHash::const_iterator iter( myHashTable.begin() );
}
Yes, it seems that the iterator does not have a default constructor.

I hope I am wrong. :)

Thanks,
Ray

The TR1 only states that the unordered_map iterators are "of at least
the forward iterator category", so I guess they have to respect the
standard requirements (which in this case means that they should have
a default constructor, as per table 74 (§24.1.3)). I'd consider this
to be a bug in the TR1 implementation that comes with g++ (but that's
not like this implementation was complete) - unless I misundertood
something.

Regards,

-- Emmanuel Deloget
If it is a bug then this bug appears in g++ (GCC) 4.0.3 (Ubuntu
4.0.3-1ubuntu5) and was fixed on or before g++ (GCC) 4.1.2 (Ubuntu
4.1.2-0ubuntu1).

Any workarounds for this bug?

Thanks a lot,
Ray
Feb 28 '07 #6
Rares Vernica wrote:
>
If it is a bug then this bug appears in g++ (GCC) 4.0.3 (Ubuntu
I used 4.0.2 to diagnose this bug. So I think it even appears earlier.
Maybe even since the inception of the 4 series?
4.0.3-1ubuntu5) and was fixed on or before g++ (GCC) 4.1.2 (Ubuntu
4.1.2-0ubuntu1).

Any workarounds for this bug?
- upgrade to 4.1.2 :)
- use ext/hash_map
- use dynamic allocation of iterators ie. "new" your iterator
and make sure to use std::tr1::shared_ptr!! :)
- always construct your iterators with stuff?
eg. unordered_map::iterator iter( foo.begin() );
Feb 28 '07 #7

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

Similar topics

3
2200
by: John Smith | last post by:
Hey I have some code which I've been using on Microsoft VC++ for some time. Now I wanted to port my application to Mac OS X which offers gcc and the build fails. Here is the troublesome code:...
5
2926
by: cayblood | last post by:
Hello, I have a vector of pointers to a class, like so: vector<Node*> m_parents; I'm having trouble creating an iterator to go through the elements in this vector. Here is my syntax: ...
9
13242
by: Prasad | last post by:
HI, I am a beginner in VC++.. I am trying to write a Win32 console application in visual studio.. I am using following header files.. #include <STRING> using namespace std; #include...
12
5684
by: arnuld | last post by:
in C++ Primer 4/3 Lippman says in chapter 3, section 3.3.1: vector<stringsvec(10); // 10 elements, each an empty string here is the the code output & output from my Debian box running "gcc...
1
1487
by: antani | last post by:
Hi, Why I get a error ?Please help me. template <typename InterceptType> class InterceptSet { public: typedef vector< InterceptType >::iterator iterator;
6
3113
by: antani | last post by:
VolumeType::ISetType::iterator findFirstIteratorMarked(const VolumeType::ISetType::iterator & it,const VolumeType::ISetType::iterator & e_it) { VolumeType::ISetType::iterator _it=it; while...
16
6045
by: Juha Nieminen | last post by:
I'm actually not sure about this one: Does the standard guarantee that if there's at least one element in the data container, then "--container.end()" will work and give an iterator to the last...
7
1647
by: utab | last post by:
Dear all, I was experimenting with a template taking two iterators for the range of a vector.(Perhaps, it is sth simple and I am missing it because it is a late hour.) I ran into problems in...
6
5764
by: abir | last post by:
Hi, I has a vector<intand i want to have some additional data associated with a few locations in the vector. i.e I want to have unordered_map<vector<int>::iterator, MyClass> so that given a...
0
7265
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
7171
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7388
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
7545
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
5692
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5095
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4751
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3228
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.