473,396 Members | 2,033 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,396 software developers and data experts.

hash_set in STL

3
I am trying to use the hash_set, but cannot get it work. Here's my code:

Expand|Select|Wrap|Line Numbers
  1.  // file name: hash1.cpp 
  2. #include <hash_set>
  3. int main()
  4. {
  5. hash_set<int> h;
  6. }
  7.  
  8. When I type:
  9. g++ -c -I/usr/include/c++/4.0.3/ext hash1.cpp 
  10.  
  11. It shows lots of errors, anyone can tell me how to use hash_set correctly? Thanks a lot! (the following are the reported errors):
  12.  
  13. /usr/include/c++/4.0.3/ext/memory:74: error: ‘std::_Temporary_buffer’ has not been declared
  14. /usr/include/c++/4.0.3/ext/memory:186: error: expected template-name before ‘<’ token
  15. /usr/include/c++/4.0.3/ext/memory:186: error: expected `{' before ‘<’ token
  16. /usr/include/c++/4.0.3/ext/memory:186: error: expected unqualified-id before ‘<’ token
  17. /usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/bits/stl_tempbuf.h: In destructor ‘std::_Temporary_buffer<_ForwardIterator, _Tp>::~_Temporary_buffer()’:
  18. /usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/bits/stl_tempbuf.h:129: error: ‘return_temporary_buffer’ is not a member of ‘std’
  19. /usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/bits/stl_tempbuf.h: In constructor ‘std::_Temporary_buffer<_ForwardIterator, _Tp>::_Temporary_buffer(_ForwardIterator, _ForwardIterator)’:
  20. /usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/bits/stl_tempbuf.h:152: error: ‘get_temporary_buffer’ was not declared in this scope
  21. /usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/bits/stl_tempbuf.h:153: error: expected primary-expression before ‘>’ token
  22. /usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/bits/stl_tempbuf.h:161: error: ‘return_temporary_buffer’ is not a member of ‘std’
  23. hash1.cpp: In function ‘int main()’:
  24. hash1.cpp:5: error: ‘hash_set’ was not declared in this scope
  25. hash1.cpp:5: error: expected primary-expression before ‘int’
  26. hash1.cpp:5: error: expected `;' before ‘int’
  27.  
Apr 5 '06 #1
5 17104
Banfa
9,065 Expert Mod 8TB
I think you need to include

Expand|Select|Wrap|Line Numbers
  1. using namespace std
  2.  
before main in order to use the STL. Also it appears that hash_set is not a mandatory member of the STL.
Apr 5 '06 #2
jian
3
Even if I add the "namespace", it still doesn't work. I know hash_set is not a member of the standard STL. But since I can find the declearation in my /usr/include/c++/4.0.3/ext/hash_set, and the library of STL is installed, I think there should be a way to use it, shouldn't it?


I think you need to include

Expand|Select|Wrap|Line Numbers
  1. using namespace std
  2.  
before main in order to use the STL. Also it appears that hash_set is not a mandatory member of the STL.
Apr 5 '06 #3
Banfa
9,065 Expert Mod 8TB
You are not declaing it correctly, you have too few items netween < and > in

Expand|Select|Wrap|Line Numbers
  1.     hash_set<int> h;
  2.  
see http://www.sgi.com/tech/stl/hash_set.html for some help
Apr 5 '06 #4
jian
3
I actually copy paste the SGI example first, but the same problem occus. So I just made a minimal example to pasted here. So I'm sure this is not the problem. To convince you, let me paste another minimal example, truncated from SGI:

Expand|Select|Wrap|Line Numbers
  1.  #include <hash_set> 
  2. using namespace std;
  3.  
  4. struct eqstr
  5. {
  6. bool operator()(const char* s1, const char* s2) const
  7. {
  8. return strcmp(s1, s2) == 0;
  9. }
  10. };
  11.  
  12. int main()
  13. {
  14. hash_set<const char*, hash<const char*>, eqstr> Set;
  15. }
  16.  
  17. And the error messages are:
  18. /usr/include/c++/4.0.3/ext/memory:74: error: ‘std::_Temporary_buffer’ has not been declared
  19. /usr/include/c++/4.0.3/ext/memory:186: error: expected template-name before ‘<’ token
  20. /usr/include/c++/4.0.3/ext/memory:186: error: expected `{' before ‘<’ token
  21. /usr/include/c++/4.0.3/ext/memory:186: error: expected unqualified-id before ‘<’ token
  22. /usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/bits/stl_tempbuf.h: In destructor ‘std::_Temporary_buffer<_ForwardIterator, _Tp>::~_Temporary_buffer()’:
  23. /usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/bits/stl_tempbuf.h:129: error: ‘return_temporary_buffer’ is not a member of ‘std’
  24. /usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/bits/stl_tempbuf.h: In constructor ‘std::_Temporary_buffer<_ForwardIterator, _Tp>::_Temporary_buffer(_ForwardIterator, _ForwardIterator)’:
  25. /usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/bits/stl_tempbuf.h:152: error: ‘get_temporary_buffer’ was not declared in this scope
  26. /usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/bits/stl_tempbuf.h:153: error: expected primary-expression before ‘>’ token
  27. /usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/bits/stl_tempbuf.h:161: error: ‘return_temporary_buffer’ is not a member of ‘std’
  28. hash1.cpp: In function ‘int main()’:
  29. hash1.cpp:14: error: ‘hash_set’ was not declared in this scope
  30. hash1.cpp:14: error: expected primary-expression before ‘const’
  31. hash1.cpp:14: error: expected `;' before ‘const’
  32.  
Apr 5 '06 #5
Hi:

I ran into the same thing as you. And I found in MS VS 2005, you need to do the following

Expand|Select|Wrap|Line Numbers
  1. using namespace stdext;
See below for what I copied from VS 2005 online help:

Members of the <hash_map> and <hash_set> header files are not currently part of the ISO C++ standard. Therefore, these types and members have been moved from the std namespace to namespace stdext, to remain conformant with the C++ standard.

When compiling with /Ze, which is the default, the compiler will warn on the use of std for members of the <hash_map> and <hash_set> header files. To disable the warning, use the warning pragma.

To have the compiler generate an error for the use of std for members of the <hash_map> and <hash_set> header files with /Ze, add the following directive before #include'ing any Standard C++ Library header files.
Apr 19 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Abhijit Ray | last post by:
I am using hash_set which is available from gcc ( and which i presume is not part of the C++ standard yet ) okay , In hash tables the key is used by a hash function to calculate a index and the...
10
by: Alex Gerdemann | last post by:
Hello, I have spent a bunch of time converting a Java program I wrote to C++ in order to improve performance, and have found that it is not necessarily faster. Specifically, I'm writing a...
5
by: Bart Blommerde | last post by:
Hi, My question is about the STL extensions hash_set and hash_map, especially the SGI versions of these templates. When defining a class like this : #include <hash_set> class MyClass : public...
1
by: Timo Qvist | last post by:
Hi, I'm a bit new to STL and really new to SGI's hash_set implementation and I've having problem instantiating a hash_set with a custom hash function, I could really use some help sifting through...
3
by: Markus Dehmann | last post by:
I have a class "Data" and I store Data pointers in an STL set. But I have millions of inserts and many more lookups, and my profiler found that they cost a lot of runtime. Therefore, I want to...
1
by: zs | last post by:
Hi! I get warning message shown below in VS.NET 2k3. Is this deprecated by microsoft or by standard? I need hash_set to store and search small strings (<20 chars long). I'll have less then 300...
8
by: Rakesh | last post by:
Hi - What is wrong this implementation? I get a core dump at the free() statement? Thanks Rakesh #include <ext/hash_map> #include <iostream.h> #include <ext/hash_set>
2
by: Pierre Couderc | last post by:
Generally, is there somewhere a good tutorial and examplefor the use of SGI STL hash_set? I am lost in SGI documentation. More specifically, i am trying to use hat I need that a hash_set : ...
5
by: Markus Dehmann | last post by:
Do I have to handle hash collisions in a hash_set myself? I did a test in which I use find() to look for objects in a hash_set. These objects are definitely not contained, but find() sometimes...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...

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.