Re: Declaring iterators
"desktop" writes:
That construct is for the STL and arrays are not part of the STL. If you
want to implement the *properties* of an iterator, go ahead and write
one. But you can't use the one from STL.
Ok so if I want a generic function that works correctly on both int arrays
and vectors, I have to write a new iterator?
How do I check if an iterator has the right type?
I have read that you don't declare an iterator type like Forward, its up
to the function that you implement to make sure that it will satisfy the
properties of a Forward iterator.
That means that it is only by inspecting a function you can see which
iterators are supported. The compiler will not generate any error if I
have an iterator "iter" and then type:
This will probably not prove helpful but I have the general feeling you are
trying to make a silk purse out of a sow's ear. As I see it you want a
seamless way to handle arrays and vectors. But arrays are not containers.
They are not even classes. Containers have properties like front, back,
size and on and on till the head swims. Arrays don't have those things. If
you want to iterate through arrays, then do so. But it won't be an array
any more because an array doesn't have something as elementary as size
specified. IOW, as I see it, you are on the road to inventing the C++
vector.