This is the mail archive of the pthreads-win32@sourceware.org mailing list for the pthreas-win32 project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Using pthread_t as a key in a map


Hi Paolo,

Bear in mind that pthreads-win32 is written in C, and operator
overloading is a C++ feature, so adding that would prevent
pthreads-win32 from compiling with C apps.

One alternative is to make a custom comparator type and use that in the
map declaration - or you could even simply move those operator overloads
to your own units (they don't have to be defined where the type being
compared is declared, as long as they've visible at the point where
they're used - ie. your map declaration).

But bear in mind that in any case, making use of the ptw32_handle_t type
makes your code nonportable, and since portability is generally the
reason one is using pthreads-win32 in the first place, this is perhaps
not the best design for general use.

Will


Paolo Brandoli wrote:
> I have a source code that uses the pthread_t as a key in a std::map.
> Because pthread-win32 defines pthread_t as a structure, the
> compilation fails.
>
> I added the following lines in my pthread.h header in order to allow
> the usage of pthread_t in the map:
>
> bool operator < (const ptw32_handle_t& left, const ptw32_handle_t& right)
> {
>    return left.p < right.p;
> }
>
> bool operator > (const ptw32_handle_t& left, const ptw32_handle_t& right)
> {
>    return left.p > right.p;
> }
>
> Bye
> Paolo Brandoli
> http://www.puntoexe.com
>


-- 
Will Bryant




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]