C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Tutorial and example to SGI STL hash_set

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Pierre Couderc
Guest





PostPosted: Thu Dec 28, 2006 10:10 am    Post subject: Tutorial and example to SGI STL hash_set Reply with quote



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 :

hash_set<c> h;

and logically the h function for my c class is missing and I get a
compile error.

How do I declare this hash function?
Back to top
Guest






PostPosted: Sat Dec 30, 2006 10:10 am    Post subject: Re: Tutorial and example to SGI STL hash_set Reply with quote



Thank you,
It is exactly the example that was missing me. I am sure that it will
be useful tou those who will be looking for "hash-set tutorial"...
The exact syntax of the hash function in not evident for me, even it it
should...
Thank you again,
Pierre



On Dec 28, 4:26 pm, "mlimber" <mlim...@gmail.com> wrote:
Quote:
Pierre Couderc wrote:
Generally, is there somewhere a good tutorial and examplefor the use of
SGI STL hash_set?I don't know, but you can get a tutorial for the very similar and
nearly standardized std::tr1::unordered_set in Pete Becker's book on
TR1.

I am lost in SGI documentation.

More specifically, i am trying to use hat I need that a hash_set :

hash_set<c> h;

and logically the h function for my c class is missing and I get a
compile error.

How do I declare this hash function?You need to specialize the hash functor for your class:

#include <hash_set

class C { /*...*/ };

// Hashable classes must have an == operator
// We'll just stub it out here, pending definition of C
bool operator==( const C&, const C& ) { return true; }

namespace std
{
template<> struct hash<C
{
// Define the hash function. We'll just stub it out here.
size_t operator()( const C& ) const { return 0; }
};
}

void hash_set_test()
{
C c;
std::hash_set<C> hsc;
hsc.insert( c );
}

Cheers! --M
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.