All these happen in VC++ NET 2003, if you ask me about the compiler.
it._Myptr is a VC++ specific member of the iterator implementation.
But from this, we extract usefull informations about crash.
----------------------------
vector<int*> v;
vector<int*>::i terator it = v.begin(); // it._Myptr == 0 (what pointer
is this?)
v.insert(it, 5); // works
it++; // it._Myptr == 4
v.insert(it, 5); // crashes
----------------------------
and this.
----------------------------
vector<int*> v;
vector<int*>::i terator it = v.begin(); // it._Myptr == 0
v.push_back(5);
vector<int*>::i terator it = v.begin(); // it._Myptr == 0x00323b40 (the
pointer to first element)
----------------------------
All of these are compiler bugs on iterator implementation, or I miss
something?
Thanks 4 3449
Chameleon wrote: All these happen in VC++ NET 2003, if you ask me about the compiler. it._Myptr is a VC++ specific member of the iterator implementation. But from this, we extract usefull informations about crash. ---------------------------- vector<int*> v; vector<int*>::i terator it = v.begin(); // it._Myptr == 0 (what pointer is this?)
The same as v.end(). No bug. You're not going to dereference it.
v.insert(it, 5); // works
That's okay, but invalidates "it".
it++; // it._Myptr == 4
Unfortunately, "it" is invalid.
v.insert(it, 5); // crashes
Yup.
---------------------------- and this. ---------------------------- vector<int*> v; vector<int*>::i terator it = v.begin(); // it._Myptr == 0 v.push_back(5);
This compiles?
vector<int*>::i terator it = v.begin(); // it._Myptr == 0x00323b40 (the pointer to first element) ----------------------------
All of these are compiler bugs on iterator implementation, or I miss something?
Ah, not every error is a compiler error!
Cheers, Calum
In article <ds**********@v olcano1.grnet.g r>,
Chameleon <ch******@hotma il.NOSPAM.com> wrote: All of these are compiler bugs on iterator implementation, or I miss something?
Until you know enough that you can build your own compiler, go ahead and
assume that the bug is in your code rather than the compiler's code...
Just a thought.
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Calum Grant wrote: Chameleon wrote: All these happen in VC++ NET 2003, if you ask me about the compiler. it._Myptr is a VC++ specific member of the iterator implementation. But from this, we extract usefull informations about crash. ---------------------------- vector<int*> v; vector<int*>::i terator it = v.begin(); // it._Myptr == 0 (what pointer is this?)
The same as v.end(). No bug. You're not going to dereference it.
v.insert(it, 5); // works
That's okay, but invalidates "it".
it++; // it._Myptr == 4
Unfortunately, "it" is invalid.
v.insert(it, 5); // crashes
Yup.
---------------------------- and this. ---------------------------- vector<int*> v; vector<int*>::i terator it = v.begin(); // it._Myptr == 0 v.push_back(5);
This compiles?
sorry, vector<int> v; vector<int*>::i terator it = v.begin(); // it._Myptr == 0x00323b40 (the pointer to first element) ----------------------------
All of these are compiler bugs on iterator implementation, or I miss something?
Ah, not every error is a compiler error!
of-course!
my solution is this until now:
-------------------------------------
vector<int*> v;
vector<int*>::i terator it = v.begin();
it = v.insert(it, 5);
it++;
it = v.insert(it, 5);
-------------------------------------
Chameleon wrote: vector<int*> v; vector<int*>::i terator it = v.begin(); // it._Myptr == 0 v.push_back(5); This compiles?
sorry, vector<int> v;
Okay, vector<int>. Good.
my solution is this until now:
------------------------------------- vector<int*> v; vector<int*>::i terator it = v.begin(); it = v.insert(it, 5); it++; it = v.insert(it, 5); -------------------------------------
Back to vector<int*> now? Well, in any case... line 2 above serves no
purpose. I would change this snippet to:
std::vector<int > v;
v.push_back(5);
v.push_back(5);
See? No need for iterators at all in this case. Maybe you got
confused because you didn't know about push_back? You owe it to
yourself to learn the public interface of important classes like
std::vector. It is only wafer-thin.
Luke This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Grant Edwards |
last post by:
In an interview at http://acmqueue.com/modules.php?name=Content&pa=showpage&pid=273
Alan Kay said something I really liked, and I think it applies
equally well to Python as well as the languages mentioned:
I characterized one way of looking at languages in this
way: a lot of them are either the agglutination of features
or they're a crystallization of style. Languages such as
APL, Lisp, and Smalltalk are what you might call style...
|
by: CoolPint |
last post by:
I am trying to write a generic heapsort (of course as a self-exercise)
with Iterator interface: something like blow....
But I got into trouble finding out the Iterator to the Child node. If
indexing was used, I could do something like child = hole * 2 + 1; but
since only thing the function accepts are random access Iterators, how
do I calculate the Iterator to the child node?
template <typename Iterator, typename Functor>
void...
|
by: Michael Klatt |
last post by:
I am trying to write an iterator for a std::set that allows the
iterator target to be modified. Here is some relvant code:
template <class Set> // Set is an instance of std::set<>
class Iterator
{
public :
typedef typename Set::value_type T;
typedef typename Set::iterator SetIterator;
Iterator(Set& container, const SetIterator& it);
|
by: Lorenzo Castelli |
last post by:
This is an old problem of mine.
Basically I have an abstract base class which represents a generic iterator
over a collection of elements, and various derived classes that implement
the traversing on specific data structures.
For each iterator I want to be able to specify the four possible const
combinations, corresponding to the various void* for
pointers, with the possibility to perform conversions from non-const to
const just like...
|
by: mailforpr |
last post by:
Hi.
Let me introduce an iterator to you, the so-called "Abstract Iterator"
I developed the other day.
I actually have no idea if there's another "Abstract Iterator" out
there, as I have never looked for one on the net (I did browse the
boost library though). It doesn't matter right now, anyway.
To put it simply, Abstract Iterator is mainly a wrapper class. It helps
| |
by: T.A. |
last post by:
I understand why it is not safe to inherit from STL containers, but I have
found (in SGI STL documentation) that for example bidirectional_iterator
class can be used to create your own iterator classes by inheriting from
it, ie.
class my_bidirectional_iterator : public bidirectional_iterator<double>
{
...
};
|
by: mailforpr |
last post by:
How do I do that?
The thing is, the only information I have about the iterator is the
iterator itself. No container it is belonging to or anything. Like
template<Iteratorvoid totally_isolated(Iterator& it)
{
//how do I find out if it points to the end node?
}
|
by: David Bilsby |
last post by:
All
Apologies for cross posing this but I am not sure if this is a VC 8 STL
bug or simply an invalid use of the iterator.
I have a PCI card access class which basically abstracts a third party
library from the higher level classes. This low level class is used to
allocate locked pages of memory before doing a DMA. The third party
library locks memory and returns a pointer to an internal structure,
which we can simply cast to a (void...
|
by: mkborregaard |
last post by:
Hi,
I have the weirdest problem, and I can not see what is going wrong.
I have made a 2d container class, and am implementing an iterator for that class. However, the ++ operator is behaving very strange. The implementation looks like this (there is a lot of code, but I have only included it all for consistency. The problem is quite small and local):
template<typename T> class Row<T> : public std::vector<T> {};
template<typename...
|
by: Luis Zarrabeitia |
last post by:
Hi there.
For most use cases I think about, the iterator protocol is more than enough.
However, on a few cases, I've needed some ugly hacks.
Ex 1:
a = iter() # assume you got the iterator from a function and
b = iter() # these two are just examples.
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |