match_results::reference
should be value_type&
, not const value_type&
Section: 28.6.9 [re.results] Status: C++14 Submitter: Matt Austern Opened: 2013-09-25 Last modified: 2017-07-05
Priority: 4
View all other issues in [re.results].
View all issues with C++14 status.
Discussion:
The match_results class synopsis has
typedef const value_type& const_reference; typedef const_reference reference;
We're getting too enthusiastic about types here by insisting that reference
is a const reference, even
though match_results
is a read-only container. In the container requirements table (Table 96, in section
23.2.2 [container.requirements.general] we say that Container::reference
is "lvalue of T
" and
Container::const_reference
is "const lvalue of T
".
That phrasing in the container requirements table is admittedly a little fuzzy and ought to be clarified (as discussed in
lwg issue 2182), but in context it's clear that Container::reference
ought to be a T&
even for constant containers. In the rest of Clause 23 we see that Container::reference
is T&
, not
const T&
, even for const-qualified containers and that it's T&
, not const T&
, even
for containers like set
and unordered_set
that provide const iterators only.
match_results
)
there are no operations that return Container::reference
. That's already the case, so this issue is complaining
about an unused typedef.
[2013-10-17: Daniel comments]
The std::initializer_list
synopsis, 17.10 [support.initlist] shows a similar problem:
template<class E> class initializer_list { public: typedef E value_type; typedef const E& reference; typedef const E& const_reference; […] }
Given the fact that std::initializer_list
doesn't meet the container requirements anyway (and is such a core-language related
type) I recommend to stick with the current state.
[Issaquah 2014-02-11: Move to Immediate]
Proposed resolution:
This wording is relative to N3691.
Change the class template match_results
header synopsis, 28.6.9 [re.results] p4 as indicated:
typedef const value_type& const_reference; typedefconst_referencevalue_type& reference;