Skip to contentSkip to conversation

STL - creating std::map key higher than double

DISCUSSION Luciano Moreira - igLnx 1 participant 2 messages Oct 20, 2004 – Oct 26, 2004

lore
Share & tools
lore
#0 lore raw

THE PROBLEM:
I never created a map<> object that has a key different from embbeded types. When I need a different key type, I create a union joinning my type with a large enough embbed type. A sample:

urion {
     myObject X; // Its size is less or equal to double size;
     double real_key;
};

Well, now I need a key larger than 128 bits, because it ll have about 48 bytes. I tryed to create a map like as:
typedef std::map<myKeyType, stItem, std::less< myKeyType > > tpList;

But, off course, the compiler advised me that "less<>" cannot compare "myKeyType", then I implemented a "operator<" into "myKeyType". And now the problem is with "iterator".

MY QUESTIONS:
Does exist a way to get a map<> with a customized key ? Should I fix the compiling erros, building my own objects ?

Thanks,
Luciano

#1 lore raw

Hi guys ! No aswers, no comments, no questions unil now.

I fixed the problem, if some one wants to know how, please contact me.

Regards,
Luciano

Luciano Moreira - igLnx escreveu:

Quoted 24 lines

THE PROBLEM:
I never created a map<> object that has a key different from embbeded types. When I need a different key type, I create a union joinning my type with a large enough embbed type. A sample:

urion {
     myObject X; // Its size is less or equal to double size;
     double real_key;
};

Well, now I need a key larger than 128 bits, because it ll have about 48 bytes. I tryed to create a map like as:
typedef std::map<myKeyType, stItem, std::less< myKeyType > > tpList;

But, off course, the compiler advised me that "less<>" cannot compare "myKeyType", then I implemented a "operator<" into "myKeyType". And now the problem is with "iterator".

MY QUESTIONS:
Does exist a way to get a map<> with a customized key ? Should I fix the compiling erros, building my own objects ?

Thanks,
Luciano

-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html