C++ Logo

std-discussion

Advanced search

Re: Iterators of the class template std::array

From: Jens Maurer <Jens.Maurer_at_[hidden]>
Date: Sun, 26 Sep 2021 15:08:57 +0200
On 26/09/2021 13.27, Vladimir Grigoriev via Std-Discussion wrote:
> I have run the program below using gcc 8.3 and its output is true.
>
> #include <iostream>
> #include <array>
> #include <type_traits>
>
> int main()
> {
> std::cout << std::is_same<std::array<int, 2>::iterator, std::array<int, 5>::iterator>::value
> << '\n';
>
> return 0;
> }
>
> Though if I am not mistaken there is nothing said in the Standard whether iterators of two instantiations of the class template std::array std::array<T, N1> and std::array <T, N2> have the same types of iterators.
>
> It would be useful if there was adopted in the Standard that iterators of two instantiations std::array<T, N1> and std::array<T, N2> had the same types of iterators.. In this case we could use lists of iterators for instantiations of std::array that have the same type of the first template parameter.

A range-checking implementation used to aid debugging might wish to
encoding N in the type of the iterator to detect out-of-bounds accesses.

Are there any that do it that way?

Jens

Received on 2021-09-26 08:09:03