Talk:cpp/string/basic string/front

Why not reference
Hi. Maybe this is not the proper place to ask, but does anybody know why the interface of std and std uses, as return type, the plain (const)references instead of these dedicated types: as opposed to the interface of, e.g., std. Is this divergence on purpose?

An excerpt from : {{source|1= namespace std { template, class Allocator = allocator> class basic_string { public: // types // ...   using value_type             = CharT; // ...   using reference              = value_type&; using const_reference       = const value_type&; // ...

// element access constexpr const_reference operator[](size_type pos) const; // OK - const_reference constexpr reference      operator[](size_type pos);       // OK - reference constexpr const_reference at(size_type n) const;          // OK    constexpr reference       at(size_type n);                 // OK    constexpr const CharT& front const; /* My: Wait, what? Not `const_reference`? */   constexpr CharT&       front;       /* My: ditto, `reference`? */   constexpr const CharT& back const;  /* My: ditto, `const_reference`? */   constexpr CharT&       back;        /* My: ditto, `reference`? */ }}

In the better imaginary world it should be: {{source|1= >  constexpr const_reference front const; // happiness constexpr reference      front;       // happiness constexpr const_reference back const; // happiness constexpr reference      back;        // happiness }}

Most likely, this is also connected with {{lwg|534}}.

--Space Mission (talk) 10:26, 27 March 2023 (PDT)


 * There's no reason to use or to avoid the {{tt|reference}} aliases, it's just an editorial inconsistency. Note that libstdc++, libc++ and MS stdlib all use {{tt|reference}}. If you were to make them consistent here on cppreference, more power to you --Ybab321 (talk) 11:00, 27 March 2023 (PDT)


 * Yea, this was my attempt to limelight this inconsistency. Should it be DR (too much for such a smidge change) or a letter to Thomas? I just would prefer to see this is fixed in draft/ISO first, then reflect it here.) --Space Mission (talk) 11:25, 27 March 2023 (PDT)


 * Editorial issues are raised on the github --Ybab321 (talk) 11:44, 27 March 2023 (PDT)