S
subramanian100in
consider the program x.cpp:
#include <cstdlib>
#include <iostream>
#include <string>
#include <list>
#include <algorithm>
using namespace std;
int main()
{
string str("test string");
typedef list<char> Container;
Container c(str.begin(), str.end());
Container::const_iterator cit = find(c.begin(), c.end(), 's');
Container::const_reverse_iterator crit = find(c.rbegin(),
c.rend(), 's');
return EXIT_SUCCESS;
}
I compiled it with g++3.4.3 as
g++ -std=c++98 -pedantic -Wall -Wextra x.cpp
It compiles fine.
In the line
Container::const_iterator cit = find(c.begin(), c.end(), 's');
I am assigning plain iterator to const_iterator. The ISO/IEC
14882:2003 document mentions the following in section 23.1 - Container
Requirements in the table 65.
For X::iterator, the assertion/note/pre/post-condition column says
that 'convertible to X::const_iterator'.
Now consider the line
Container::const_reverse_iterator crit = find(c.rbegin(),
c.rend(), 's');
Here I am assigning reverse_iterator to const_reverse_iterator. In ISO/
IEC 14882:2003 document, in Table 66 - 'Reversible container
requirements' the following is mentioned:
For X::reverse_iterator, the assertion/note/pre/post-condition column
says
reverse_iterator <iterator>. It doesn't say 'convertible to
X::const_reverse_iterator'.
Is it implied here ? Or will all implementations allow assignment of
reverse_iterator to const_reverse_iterator ?
Kindly clarify.
Thanks
V.Subramanian
#include <cstdlib>
#include <iostream>
#include <string>
#include <list>
#include <algorithm>
using namespace std;
int main()
{
string str("test string");
typedef list<char> Container;
Container c(str.begin(), str.end());
Container::const_iterator cit = find(c.begin(), c.end(), 's');
Container::const_reverse_iterator crit = find(c.rbegin(),
c.rend(), 's');
return EXIT_SUCCESS;
}
I compiled it with g++3.4.3 as
g++ -std=c++98 -pedantic -Wall -Wextra x.cpp
It compiles fine.
In the line
Container::const_iterator cit = find(c.begin(), c.end(), 's');
I am assigning plain iterator to const_iterator. The ISO/IEC
14882:2003 document mentions the following in section 23.1 - Container
Requirements in the table 65.
For X::iterator, the assertion/note/pre/post-condition column says
that 'convertible to X::const_iterator'.
Now consider the line
Container::const_reverse_iterator crit = find(c.rbegin(),
c.rend(), 's');
Here I am assigning reverse_iterator to const_reverse_iterator. In ISO/
IEC 14882:2003 document, in Table 66 - 'Reversible container
requirements' the following is mentioned:
For X::reverse_iterator, the assertion/note/pre/post-condition column
says
reverse_iterator <iterator>. It doesn't say 'convertible to
X::const_reverse_iterator'.
Is it implied here ? Or will all implementations allow assignment of
reverse_iterator to const_reverse_iterator ?
Kindly clarify.
Thanks
V.Subramanian