I am writing a stl-like container class which has the following functions:
Iterator begin(){
return Iterator(data_.begin(), 1);
}
ConstIterator begin() const{
return ConstIterator(data_.begin(), 1);
}
I think I could make one function to replace both:
template <typename itr0, typename itr1>
itr0 begin(){
return itr1(data_.begin(), 1);
}
and when I call the following, the code is generated in compile time:
Iterator it = foo.begin<Iterator, Iterator>();
ConstIterator it = foo.begin<ConstIterator const?, ConstIterator>();
My first question is, what typename is actually ConstIterator begin() const
?
Secondly, is there a way to make it so that this metaprogramming is transparent from outside of the class? i.e. I could still use the following code to call begin() as if it was written in a standard way?
C foo;
const C foo2;
Iterator it = foo.begin();
ConstIterator it = foo2.begin();