Can I assume the memory is continuous?

R

Richard Herring

Juha Nieminen said:
The original claim was that "comparing vector iterators with < will
always work because iterators work like smart pointers".

Exactly what are these "additional features" of vector iterators,
compared to raw pointers, which allow comparing them with the < operator?

Why would comparison need to be an "additional" feature? Surely one
aspect of being a smart pointer is that they provide _at least_ the same
behaviour as the corresponding kind of raw pointer.
My objection was that the claim makes no sense because *regular* raw
pointers can be compared with the < operator

(Incidentally, though it's not relevant here, this is not true if they
don't point into the same array or to members of the same object.
std::less may have to use compiler magic to ensure that it can compare
arbitrary pointers.)
and vector iterators having
the same property doesn't make them any "smarter".

Besides, as wikipedia hints, smart pointers in C++ are almost
exclusively used for memory management.

Not just (or even principally) memory -- new and delete do a lot more
than malloc and free. How about higher-level concepts like lifetime and
transfer of ownership?
I would say that to the point
that "smart pointer" in C++ *means* "a pointer which manages the memory
it points to".

Change that to "the _object_ it points to". Objects are not just memory.
I'm not the only one who thinks like this. Look for
example at:

http://www.boost.org/libs/smart_ptr/smart_ptr.htm

"Smart pointers are objects which store pointers to dynamically
allocated (heap) objects. They behave much like built-in C++ pointers
except that they automatically delete the object pointed to at the
appropriate time."

That says "delete the object", not "free the memory".
Maybe the boost documentation is also "of mixed quality".

Maybe the boost documentation only describes the boost smart pointers.
 
P

Pete Becker

Besides, as wikipedia hints, smart pointers in C++ are almost
exclusively used for memory management. I would say that to the point
that "smart pointer" in C++ *means* "a pointer which manages the memory
it points to". I'm not the only one who thinks like this. Look for
example at:

http://www.boost.org/libs/smart_ptr/smart_ptr.htm

"Smart pointers are objects which store pointers to dynamically
allocated (heap) objects. They behave much like built-in C++ pointers
except that they automatically delete the object pointed to at the
appropriate time."

Maybe the boost documentation is also "of mixed quality".

It certainly is. It takes a great deal of work to convert the Boost
documentation into proper specifications when Boost libraries are
incorporated into the language standard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top