Skip to content

Resolve "Wdeprecated-declarations warnings on std::iterator"

Closes #2617 (closed).

I took this article as inspiration and the code for std::string_view which looks like this under /usr/aarch64-linux-gnu/include/c++/12.2.0/string_view:

  template<typename _CharT, typename _Traits = std::char_traits<_CharT>>
    class basic_string_view
    {
      static_assert(!is_array_v<_CharT>);
      static_assert(is_trivial_v<_CharT> && is_standard_layout_v<_CharT>);
      static_assert(is_same_v<_CharT, typename _Traits::char_type>);

    public:

      // types
      using traits_type		= _Traits;
      using value_type		= _CharT;
      using pointer		= value_type*;
      using const_pointer	= const value_type*;
      using reference		= value_type&;
      using const_reference	= const value_type&;
      using const_iterator	= const value_type*;
      using iterator		= const_iterator;
      using const_reverse_iterator = std::reverse_iterator<const_iterator>;
      using reverse_iterator	= const_reverse_iterator;
      using size_type		= size_t;
      using difference_type	= ptrdiff_t;
      static constexpr size_type npos = size_type(-1);

I thought about writing more unit tests to test for the iterator behavior, but I think the current tests should be enough.

Edited by Andrei Pavel

Merge request reports