Topic: iterator requirements
Author: James Kuyper <kuyper@wizard.net>
Date: 1999/03/29 Raw View
John Aldridge wrote:
>
> I'd be grateful for some assistance interpreting the standard...
>
> 1. Does the type
>
> std::auto_ptr<T> *
>
> (for some type T) meet the standard's requirements for all iterator
> categories?
Yes, it's an ordinary pointer (to an auto_ptr), and iterators were
concieved of as an extension of pointers; pointers automatically meet
all of the iterator requirements. auto_ptr<T> itself, of course, isn't
an iterator at all - it meets the requirements for none of the
categories.
> 2. Assuming it does meet the requirements of an input iterator, does the
> standard therefore guarantee that
>
> typedef std::auto_ptr<char> APC;
> APC data[6];
> for (int i = 0; i < 6; ++i) data[i].reset (new char ("314159"[i]));
>
> struct P1 {
> bool operator () (const APC &p) const { return *p < '4'; }
> };
> cout << std::count_if (data, data+6, P1 ()) << endl;
>
> will print the value "3"?
>
> 3. Assuming it does meet the requirements of a bi-directional iterator,
> does the standard therefore guarantee that
>
> struct CP {
> bool operator () (const APC &lhs, const APC &rhs) const
> { return *lhs < *rhs; }
> };
> std::sort (data, data+6, CP());
> for (int j = 0; j < 6; ++j) cout << *data[j];
> cout << endl;
Seems reasonable to me.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: John Aldridge <jpsa@jjdash.demon.co.uk>
Date: 1999/03/29 Raw View
I'd be grateful for some assistance interpreting the standard...
1. Does the type
std::auto_ptr<T> *
(for some type T) meet the standard's requirements for all iterator
categories?
2. Assuming it does meet the requirements of an input iterator, does the
standard therefore guarantee that
typedef std::auto_ptr<char> APC;
APC data[6];
for (int i = 0; i < 6; ++i) data[i].reset (new char ("314159"[i]));
struct P1 {
bool operator () (const APC &p) const { return *p < '4'; }
};
cout << std::count_if (data, data+6, P1 ()) << endl;
will print the value "3"?
3. Assuming it does meet the requirements of a bi-directional iterator,
does the standard therefore guarantee that
struct CP {
bool operator () (const APC &lhs, const APC &rhs) const
{ return *lhs < *rhs; }
};
std::sort (data, data+6, CP());
for (int j = 0; j < 6; ++j) cout << *data[j];
cout << endl;
(given the same initialisation for data as Q2) will print "113459"?
If the answer to any of these questions is "No", I'd appreciate chapter
& verse, because I've looked and can't find it.
--
Cheers,
John
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]