This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


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

map,const keytype



Hello,

I don't think this is the appropriate list, but nevertheless, I am hoping
for some friendly help on this question:

Can the Key type parameter in the template map be const?

The Sun compiler is giving an error when declaring a map with 'const int' as
a key type. gcc does not give an error. The Sun compiler team claims that
the code violates the standard.

The standard says:

>>From the C++ standard:
>>    Table 69 in 23.1.2, p7, says that
>>    X::key_type must be assignable;

The code is:

>>--------------------------------------------------
>>% cat map.cpp
>>--------------------------------------------------
>>#include <map>
>>
>>class DE_SQL
>>{
>>public:
>> DE_SQL(void);
>>protected:
>> std::map<const int, int> mTable;
>>};
>>
>>DE_SQL::DE_SQL(void)
>>{
>>}
>>--------------------------------------------------
>>% CC6 -V -c map.cpp
>>CC6: Sun WorkShop 6 00/03/06 C++ 5.1
>>ccfe: Sun WorkShop 6 00/03/06 C++ 5.1
>>"/workspace/.mnt/buffy3/markw/buildbin-030600/SC5.1/include/CC/Cstd/map",
>>line 251: Error: Multiple declaration for std::map<const int, int,
>>std::less<const int>, std::allocator<std::pair<const int,
>>int>>>::insert(const std::pair<const int, int>&).
>>"map.cpp", line 9: Where: While specializing "std::map<const int, int,
>>std::less<const int>, std::allocator<std::pair<const int, int>>>".
>>"map.cpp", line 9: Where: Specialized in non-template code.
>>1 Error(s) detected.
>>--------------------------------------------------

Now, I am puzzled as to why key_type needs to be assignable? There is no
interface function that seems to need to assign to an element. So, it could
be something "under the hood" that needs assignment. I tried doing several
things with maps after putting a message in the assignment operator code for
the key, but I could never get it to execute. Does anybody know why the
standard would require key_type to be assignable?

Is it possible that the standard is in error? I. e. they mistakenly put the
Assignable requirement? I am pretty sure that the standard is not in error
but just wanted to be sure.

Thanks very much,

Anjul.

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