S
subramanian100in
I want to understand how 'rbegin() const' returns a
std::const_reverse_iterator.
Kindly go through the following and correct me where-ever I am wrong.
I am using g++ 3.4.3. In this implementation, 'rbegin() const' is
defined as
const_reverse_iterator
rbegin() const { return const_reverse_iterator(end()); }
Here 'rbegin() const' returns std::const_reverse_iterator(end())
which is the same as std::reverse_iterator<const_iterator>(end()). In
this, the return type of end() is 'iterator'. So we essentially have
std::reverse_iterator<const_iterator>(iterator). This has to invoke
the following converting ctor in reverse_iterator class template:
template <class U>
reverse_iterator(const reverse_iterator<U>& u);
But for this to take place, the RHS argument in
std::reverse_iterator<const_iterator>(iterator) must be
reverse_iterator<iterator>. Since we only have 'iterator', it must be
converted to reverse_iterator<iterator> using the ctor
explicit reverse_iterator(Iterator x);
But, as mentioned, this ctor is declared 'explicit'. So I am unable to
understand how the implicit conversion of 'iterator' in
std::reverse_iterator<const_iterator>(iterator) to
reverse_iterator<iterator> can happen.
we have:
std::reverse_iterator<const_iterator>(iterator)
This has to be converted to:
std::reverse_iterator<const_iterator>(
reverse_iterator<iterator>);
Then only the latter can invoke the converting ctor in
reverse_iterator class template. Is this understanding of mine is
correct ?
Kindly clarify.
Thanks
V.Subramanian
std::const_reverse_iterator.
Kindly go through the following and correct me where-ever I am wrong.
I am using g++ 3.4.3. In this implementation, 'rbegin() const' is
defined as
const_reverse_iterator
rbegin() const { return const_reverse_iterator(end()); }
Here 'rbegin() const' returns std::const_reverse_iterator(end())
which is the same as std::reverse_iterator<const_iterator>(end()). In
this, the return type of end() is 'iterator'. So we essentially have
std::reverse_iterator<const_iterator>(iterator). This has to invoke
the following converting ctor in reverse_iterator class template:
template <class U>
reverse_iterator(const reverse_iterator<U>& u);
But for this to take place, the RHS argument in
std::reverse_iterator<const_iterator>(iterator) must be
reverse_iterator<iterator>. Since we only have 'iterator', it must be
converted to reverse_iterator<iterator> using the ctor
explicit reverse_iterator(Iterator x);
But, as mentioned, this ctor is declared 'explicit'. So I am unable to
understand how the implicit conversion of 'iterator' in
std::reverse_iterator<const_iterator>(iterator) to
reverse_iterator<iterator> can happen.
we have:
std::reverse_iterator<const_iterator>(iterator)
This has to be converted to:
std::reverse_iterator<const_iterator>(
reverse_iterator<iterator>);
Then only the latter can invoke the converting ctor in
reverse_iterator class template. Is this understanding of mine is
correct ?
Kindly clarify.
Thanks
V.Subramanian