473,224 Members | 1,410 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

VS 2005 should allows this, why?

#include <set>

using namespace std;

int main()
{

typedef set<intINTSET;

INTSET coll;

INTSET::iterator pos = coll.begin();

*pos = 9; // VS 2005 should allowes this, why?

}

the set will contain two same values, it violates the rule that a set
at most contains one of each key value.

Jul 8 '06 #1
10 1473
Lighter wrote:
#include <set>

using namespace std;

int main()
{

typedef set<intINTSET;
All caps is usually used form macros.
INTSET coll;

INTSET::iterator pos = coll.begin();

*pos = 9; // VS 2005 should allowes this, why?
Why should it and why VS 2005 in particular?

--
Ian Collins.
Jul 8 '06 #2
Lighter wrote:
#include <set>

using namespace std;

int main()
{

typedef set<intINTSET;

INTSET coll;

INTSET::iterator pos = coll.begin();

*pos = 9; // VS 2005 should allowes this, why?
No C++ compiler will allow this.

At the point of the above statement pos has the value
of coll.end(). You can't dereference it.

I think you have the concept of iterators and inserters
confused.
Jul 8 '06 #3
Lighter wrote:
#include <set>

using namespace std;

int main()
{

typedef set<intINTSET;

INTSET coll;

INTSET::iterator pos = coll.begin();

*pos = 9; // VS 2005 should allowes this, why?
At this point, you have undefined behavior, and ANYTHING can happen.
}
Jul 8 '06 #4
red floyd wrote:

At this point, you have undefined behavior, and ANYTHING can happen.
=============

I'm sorry for my careless. I made a typying mistake. The actual code
fragment is as follows:

#include <set>

using namespace std;
int main()
{

typedef set<intINTSET;

INTSET coll;

coll.insert(9); // This line was omitted before

INTSET::iterator pos = coll.begin();
*pos = 9; // VS 2005 should allowes this, why?

}

Jul 8 '06 #5
Lighter wrote:
red floyd wrote:

At this point, you have undefined behavior, and ANYTHING can happen.
=============

I'm sorry for my careless. I made a typying mistake. The actual code
fragment is as follows:
That's why you should always copy and paste, not retype.
#include <set>

using namespace std;
int main()
{

typedef set<intINTSET;

INTSET coll;

coll.insert(9); // This line was omitted before

INTSET::iterator pos = coll.begin();
*pos = 9; // VS 2005 should allowes this, why?
Again, I ask why VS 2005 and why should it allow it?

--
Ian Collins.
Jul 8 '06 #6

"Ian Collins" <ia******@hotmail.comskrev i meddelandet
news:4h**************@individual.net...
Lighter wrote:
>red floyd wrote:

At this point, you have undefined behavior, and ANYTHING can
happen.
=============

I'm sorry for my careless. I made a typying mistake. The actual
code
fragment is as follows:
That's why you should always copy and paste, not retype.
>#include <set>

using namespace std;
int main()
{

typedef set<intINTSET;

INTSET coll;

coll.insert(9); // This line was omitted before

INTSET::iterator pos = coll.begin();
*pos = 9; // VS 2005 should allowes this, why?
Again, I ask why VS 2005 and why should it allow it?
I think the OP might be referring to this defect report for C++

http://www.open-std.org/jtc1/sc22/wg...fects.html#103

which asks if you are allowed to change the value of the map elements.

The original standard is obviously a bit unclear on this, which
explains why implementations behave inconsistently.
So, my attempt to answer the question is:

It might (right now) be ok to do *pos=9, if pos is a valid iterator,
and assigning the value 9 doesn't change the order of the elements in
the set.

It seems like the next revision of the standard will contain the
sentence "Keys in an associative container are immutable.", which will
change the rule.
Bo Persson
Jul 9 '06 #7
Bo Persson wrote:
"Ian Collins" <ia******@hotmail.comskrev i meddelandet
news:4h**************@individual.net...
>>Lighter wrote:
>>>*pos = 9; // VS 2005 should allowes this, why?

Again, I ask why VS 2005 and why should it allow it?


I think the OP might be referring to this defect report for C++

http://www.open-std.org/jtc1/sc22/wg...fects.html#103

which asks if you are allowed to change the value of the map elements.

The original standard is obviously a bit unclear on this, which
explains why implementations behave inconsistently.
So, my attempt to answer the question is:

It might (right now) be ok to do *pos=9, if pos is a valid iterator,
and assigning the value 9 doesn't change the order of the elements in
the set.

It seems like the next revision of the standard will contain the
sentence "Keys in an associative container are immutable.", which will
change the rule.
That makes sense. Both the compilers I use enforce this.

--
Ian Collins.
Jul 9 '06 #8
I think, as a solution, the c++ standard should cancel the interface
iterator of set intead of the only interface const_iterator that users
can get under any circumstance.

for exmaple, the following code should not be allowed:

set<int>::iterator pos; // error, set doesn't provide a type/interface
named iterator

in contrast, the following is allowed

set<int>::const_iterator pos; // This should be the only way to declare
a iterator of set

Jul 9 '06 #9
In message <11**********************@h48g2000cwc.googlegroups .com>,
Lighter <cq****@gmail.comwrites
>I think, as a solution, the c++ standard should cancel the interface
iterator of set intead of the only interface const_iterator that users
can get under any circumstance.

for exmaple, the following code should not be allowed:

set<int>::iterator pos; // error, set doesn't provide a type/interface
named iterator

in contrast, the following is allowed

set<int>::const_iterator pos; // This should be the only way to declare
a iterator of set
If you did that, you'd have to remove the overloads of erase() that take
iterators. Not such a good idea.

--
Richard Herring
Jul 10 '06 #10
Lighter <cq****@gmail.comwrites
I think, as a solution, the c++ standard should cancel the interface
iterator of set intead of the only interface const_iterator that users
can get under any circumstance.

for exmaple, the following code should not be allowed:

set<int>::iterator pos; // error, set doesn't provide a type/interface
named iterator

in contrast, the following is allowed

set<int>::const_iterator pos; // This should be the only way to declare
a iterator of set
Interestingly I just read Item 22 in "Effective STL" by Scott Meyers
which deals with this issue. In short, iterators are needed to change
the "non-key" parts of a set element. In your case, the element is just
an int so it is not relevant.

Jul 10 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Unigroup of New York | last post by:
Content-Type: multipart/mixed; boundary="------------C465DF38DCB38DD2AF7117E0" Lines: 327 Date: Tue, 15 Feb 2005 23:36:38 -0500 NNTP-Posting-Host: 24.46.113.251 X-Complaints-To: abuse@cv.net...
3
by: Peter Morris | last post by:
What's the deal with SQLServer 2005 Beta? I've just got a magazine with a free cover disk with VB 2005 beta, and also includes SQLServer 2005. I've installed it, but I can't get it to do...
3
by: Mike P | last post by:
I've been using Visual Studio 2005 Beta 1 for the last few weeks, and I now want to try using SQL Server 2005 Beta with it. I've been to the Microsoft URL...
5
by: ad | last post by:
Hi, What is the difference between Visual Studio.NET 2005 ©MVisual Web Developer 2005 Express ?
13
by: Howard Kaikow | last post by:
I just visited the MSFT web site and saw the comparison/pricing of the different VS 2005 versions. I was looking for a statement of the system requirements for VS Pro and VSTO, could not find. ...
0
by: fiona | last post by:
Innovasys Ltd., a leader in help authoring and documentation tools, today announced the inclusion of a tailored version of the Innovasys HelpStudio help authoring product, HelpStudio Lite, in the...
9
by: Leon | last post by:
Hi Everybody. I have my website developed in VS 2003. Now I want to upgrade my website to VS 2005 and develop new web pages in a new environment. What steps should I take to upgrade? I cannot find...
2
by: Luke.Schollmeyer | last post by:
I found an unusual problem between 2000 and 2005 I haven't been able to decipher from any documentation. The query structure is as follows: select * from tableA a join tableB b ON...
5
by: jehugaleahsa | last post by:
Does SQL Server 2005 Allows NULL for DateTime? Just checking.
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.