Title
quoted()'s interaction with padding is unclear
Status
c++14
Section
[quoted.manip]
Submitter
Stephan T. Lavavej

Created on 2013-11-01.00:00:00 last changed 123 months ago

Messages

Date: 2014-02-14.21:13:25

Proposed resolution:

This wording is relative to N3797.

  1. Edit [quoted.manip] as follows:

    template <class charT>
      unspecified quoted(const charT* s, charT delim=charT('"'), charT escape=charT('\\'));
    template <class charT, class traits, class Allocator>
      unspecified quoted(const basic_string<charT, traits, Allocator>& s,
                         charT delim=charT('"'), charT escape=charT('\\'));
    

    -2- Returns: An object of unspecified type such that if out is an instance of basic_ostream with member type char_type the same as charT, then the expression out << quoted(s, delim, escape) behaves as if it inserts the following characters into out using character inserter function templates (27.7.3.6.4), which may throw ios_base::failure (27.5.3.1.1)a formatted output function ([ostream.formatted.reqmts]) of out. This forms a character sequence seq, initially consisting of the following elements:

    • delim.

    • Each character in s. If the character to be output is equal to escape or delim, as determined by operator==, first output escape.

    • delim.

    Let x be the number of elements initially in seq. Then padding is determined for seq as described in [ostream.formatted.reqmts], seq is inserted as if by calling out.rdbuf()->sputn(seq, n), where n is the larger of out.width() and x, and out.width(0) is called. The expression out << quoted(s, delim, escape) shall have type basic_ostream<charT, traits>& and value out.

Date: 2014-02-14.00:00:00

[ 2014-02-14 Issaquah meeting: Move to Immediate ]

Date: 2013-11-01.00:00:00

Given this code:

cout << "[" << left << setfill('x') << setw(20) << R"("AB \"CD\" EF")" << "]" << endl;
cout << "[" << left << setfill('y') << setw(20) << quoted(R"(GH "IJ" KL)") << "]" << endl;

The first line prints ["AB \"CD\" EF"xxxxxx]. The second line should probably print ["GH \"IJ\" KL"yyyyyy], but [quoted.manip]/2 doesn't say whether or how quoted() should interact with padding. All it says is that

"out << quoted(s, delim, escape) behaves as if it inserts the following characters into out using character inserter function templates (27.7.3.6.4)".

[ostream.inserters.character] specifies both single-character and null-terminated inserters, both referring to [ostream.formatted.reqmts]/3 for padding. Literally implementing quoted() with single-character inserters would result in padding being emitted after the first character, with undesirable effects for ios_base::left.

It appears that [string.io]/5 has the appropriate incantations to follow here. It says that os << str

"Behaves as a formatted output function (27.7.3.6.1) of os. Forms a character sequence seq, initially consisting of the elements defined by the range [str.begin(), str.end()). Determines padding for seq as described in 27.7.3.6.1. Then inserts seq as if by calling os.rdbuf()->sputn(seq, n), where n is the larger of os.width() and str.size(); then calls os.width(0)."

Additionally, saying that it's a "formatted output function" activates [ostream.formatted.reqmts]/1's wording for sentry objects.

History
Date User Action Args
2014-02-27 17:03:20adminsetstatus: wp -> c++14
2014-02-20 13:52:38adminsetstatus: immediate -> wp
2014-02-14 21:13:25adminsetmessages: + msg6872
2014-02-14 21:13:25adminsetstatus: new -> immediate
2014-01-12 13:04:52adminsetmessages: + msg6774
2013-11-01 00:00:00admincreate