Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old August 19th, 2005, 07:55 PM
Garrett Kajmowicz
Guest
 
Posts: n/a
Default Const types in map

Is the following legal:

std::map<int, const int> q;

In short, does the const int violate the Container requirements in 23.1.3
that the types be assignable?

Thanks.

- Garrett
  #2  
Old August 19th, 2005, 09:25 PM
Esteban Osses
Guest
 
Posts: n/a
Default Re: Const types in map

I'd say it's legal.
The type is assignable, however there is a constraint on using the
assignment operator (and any other method/operator modifying its
content).
To insert a new item in such a map you can always do:

q.insert( std::pair<int, const int>(3, 5) );

but
q[ 3 ] = 5;

is not allowed

--
Esteban

  #3  
Old August 20th, 2005, 02:25 PM
Garrett Kajmowicz
Guest
 
Posts: n/a
Default Re: Const types in map

[color=blue]
> I'd say it's legal.
> The type is assignable, however there is a constraint on using the
> assignment operator (and any other method/operator modifying its
> content).
> To insert a new item in such a map you can always do:
>
> q.insert( std::pair<int, const int>(3, 5) );
>
> but
> q[ 3 ] = 5;
>
> is not allowed[/color]

My understanding is that 23.1.4 (Table 2) has the following requirements:

Table 2--Assignable requirements

+------------------------------------------------+
|expression return type post-condition |
+------------------------------------------------+
|t = u T& t is equivalent to u |
+------------------------------------------------+

How does that make a const type assignable for the purposes of map?

- Garrett
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles