2938. basic_string_view::const_iterator should be literal types

Section: 24.4.2 [string.view.template] Status: New Submitter: Antony Polukhin Opened: 2017-03-01 Last modified: 2017-11-13

Priority: 2

View all issues with New status.

Discussion:

Force the literal type requirement for the const_iterator in the std::basic_string_view so that iterators of std::basic_string_view could be used in constexpr functions.

[2017-03-02, Kona]

Wording tweaks suggested by LWG applied.

[2017-03-02, Tim Song comments]

I don't believe the blanket "all operations" wording is quite correct.

First, T t; (required by DefaultConstructible) isn't usable in a constant expression if the iterator is a pointer, since it would leave it uninitialized.

Second, an explicit destructor call u.~T() (required by Destructible) isn't usable if the iterator is a class type because it explicitly invokes a non-constexpr function (the destructor); see [expr.const]/2.2.

[2017-03-04, Kona]

Set priority to 2. Lisa and Alisdair to work with Antony to come up with better wording. The same wording can be used for 2897.

[2017-11 Albuquerque Saturday issues processing]

P0858R0 (adopted on Sat; to be moved in Jacksonville) will resolve this.

Proposed resolution:

This wording is relative to N4640.

  1. Add to the end of the 24.4.2 [string.view.template] section:

    -1- In every specialization basic_string_view<charT, traits>, the type traits shall satisfy the character traits requirements (21.2), and the type traits::char_type shall name the same type as charT.

    -?- All operations on iterator and const_iterator that are required to satisfy the random access iterator requirements are usable in constant expressions.