error with tr1 unordered_map iterator

Discussion in 'C++' started by Rares Vernica, Feb 24, 2007.

  1. 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, unsigned> StringHash;
    ....
    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, unsigned> StringHash;
    ....
    typedef set<unsigned> WordLevelEntrySet;
    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
    Rares Vernica, Feb 24, 2007
    #1
    1. Advertising

  2. Rares Vernica

    Piyo Guest

    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, unsigned> StringHash;
    > ...
    > 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, unsigned> StringHash;
    > ...
    > typedef set<unsigned> WordLevelEntrySet;
    > 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


    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
    Piyo, Feb 25, 2007
    #2
    1. Advertising

  3. Rares Vernica

    Piyo Guest

    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, unsigned> StringHash;
    > ...
    > 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, unsigned> StringHash;
    > ...
    > typedef set<unsigned> WordLevelEntrySet;
    > 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, unsigned> StringHash;

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

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

    }
    Piyo, Feb 27, 2007
    #3
  4. 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, unsigned> StringHash;
    >> ...
    >> 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, unsigned> StringHash;
    >> ...
    >> typedef set<unsigned> WordLevelEntrySet;
    >> 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, unsigned> StringHash;
    >
    > 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
    Rares Vernica, Feb 27, 2007
    #4
  5. On 28 fév, 00:07, Rares Vernica <> wrote:
    > 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, unsigned> StringHash;
    > >> ...
    > >> 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, unsigned> StringHash;
    > >> ...
    > >> typedef set<unsigned> WordLevelEntrySet;
    > >> 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, unsigned> StringHash;

    >
    > > 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
    Emmanuel Deloget, Feb 28, 2007
    #5
  6. Emmanuel Deloget wrote:
    > On 28 fév, 00:07, Rares Vernica <> wrote:
    >> 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, unsigned> StringHash;
    >>>> ...
    >>>> 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, unsigned> StringHash;
    >>>> ...
    >>>> typedef set<unsigned> WordLevelEntrySet;
    >>>> 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, unsigned> StringHash;
    >>> 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
    Rares Vernica, Feb 28, 2007
    #6
  7. Rares Vernica

    Piyo Guest

    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() );
    Piyo, Feb 28, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Emmanuel Deloget
    Replies:
    3
    Views:
    392
    Chris Thomasson
    Mar 3, 2007
  2. Fokko Beekhof

    std::tr1::array iterator types

    Fokko Beekhof, Apr 7, 2008, in forum: C++
    Replies:
    1
    Views:
    446
    Bo Persson
    Apr 7, 2008
  3. abir
    Replies:
    6
    Views:
    834
    W Karas
    Jun 26, 2008
  4. Replies:
    3
    Views:
    1,781
  5. Alex Wanderleit
    Replies:
    1
    Views:
    848
    Marcel Müller
    Jan 5, 2011
Loading...

Share This Page