473,382 Members | 1,373 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,382 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 1481
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
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.