Topic: Iterators conversion requirements
Author: rani_sharoni@hotmail.com ("Rani Sharoni")
Date: Mon, 14 Apr 2003 03:06:01 +0000 (UTC) Raw View
Hello All,
My friend implemented STL like vector for environment without C++ exceptions
and during the code review we wondered what kind of conversion from iterator
to const_iterator is required (i.e. standard or user defined).
Consider the following code:
#include <vector>
struct A {};
struct B {
B(std::vector<A>::const_iterator);
};
extern std::vector<A> v;
B b = v.begin();
The code will work if the iterator has standard conversion to const_iterator
which means that the implementation is using pointers or derivation. The
code will not work if the conversion is user defined.
I didn't find this exact conversion requirement from itreator to
const_iterator and I believe that the intention is to assume user defined
conversion.
Is it?
I compiled the code with several compliers and their default library and got
different results:
VC7.1, Comeau 4.3.0.1, GCC 2.95.3-10 and BCC 5.5 compiled the code.
VC7 and GCC3.2 failed to compile the code.
Thanks,
Rani
---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]
Author: bop2@telia.com ("Bo Persson")
Date: Mon, 14 Apr 2003 17:55:00 +0000 (UTC) Raw View
""Rani Sharoni"" <rani_sharoni@hotmail.com> skrev i meddelandet
news:3e992f87@news.microsoft.com...
> Hello All,
>
> My friend implemented STL like vector for environment without C++
exceptions
> and during the code review we wondered what kind of conversion from
iterator
> to const_iterator is required (i.e. standard or user defined).
>
> Consider the following code:
> #include <vector>
> struct A {};
> struct B {
> B(std::vector<A>::const_iterator);
> };
>
> extern std::vector<A> v;
> B b = v.begin();
>
> The code will work if the iterator has standard conversion to
const_iterator
> which means that the implementation is using pointers or derivation. The
> code will not work if the conversion is user defined.
>
> I didn't find this exact conversion requirement from itreator to
> const_iterator and I believe that the intention is to assume user defined
> conversion.
> Is it?
No, there is no such requirement. There is hardly even a requirement that
they are comparable, see DR #179:
http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-defects.html#179
Bo Persson
bop2@telia.com
---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]