|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4146" status="New"> |
| 5 | +<title>§[format.formatter.spec]/3 unconditionally enables nonlocking for container adaptors</title> |
| 6 | +<section><sref ref="[format.formatter.spec]"/><sref ref="[container.adaptors.format]"/></section> |
| 7 | +<submitter>Casey Carter</submitter> |
| 8 | +<date>31 Aug 2024</date> |
| 9 | +<priority>99</priority> |
| 10 | + |
| 11 | +<discussion> |
| 12 | +<p> |
| 13 | +<sref ref="[format.formatter.spec]"/>/3 says that the library provides a specialization of |
| 14 | +`enable_nonlocking_formatter_optimization` with value `true` corresponding to each library-provided |
| 15 | +specialization of `formatter`, unless otherwise specified. Although it actually states |
| 16 | +"for each type `T`", the intent is that partial specializations are also provided corresponding to |
| 17 | +library-provided partial specializations of formatter. |
| 18 | +<p/> |
| 19 | +<sref ref="[container.adaptors.format]"/>/1 says the library provides a partial specialization of |
| 20 | +`formatter` for each of the container adaptor templates `priority_queue`, `queue`, and `stack`. |
| 21 | +Together with <sref ref="[format.formatter.spec]"/>/3, that means that e.g. |
| 22 | +<tt>enable_nonlocking_formatter_optimization<stack<T>> == true</tt>. Formatting a stack of |
| 23 | +that type will enable the nonlocking optimization even if |
| 24 | +<tt>enable_nonlocking_formatter_optimization<T> == false</tt>. To avoid this, the author of `T` |
| 25 | +must partially specialize `enable_nonlocking_formatter_optimization` to `false` for all container |
| 26 | +adaptors when they adapt a container of `T`. |
| 27 | +<p/> |
| 28 | +It is clearly not the design intent that programmers must explicitly opt out of the nonlocking |
| 29 | +optimization, so this is a defect that LWG should correct. Since <paper num="P3235R3"/> was applied |
| 30 | +as a Defect Report to C++23, the resolution of this issue should be so applied as well. |
| 31 | +<p/> |
| 32 | +<b>Suggested Resolution:</b> |
| 33 | +<p/> |
| 34 | +LEWG was reticent to apply the optimization to general ranges — ostensibly due to the possibility |
| 35 | +of deadlock in program-defined iterator operations — but apparently unconcerned about the iterators |
| 36 | +of program-defined containers nor the fancy pointers of program-defined allocators. It seems consistent |
| 37 | +with that design to ignore the "container" part of "container adaptors" and only pay attention to the |
| 38 | +elements that are going to be formatted. (I have prototyped this resolution on MSVCSTL, albeit slightly |
| 39 | +modified since neither MSVC nor Clang like this partial specialization form.) |
| 40 | +</p> |
| 41 | +</discussion> |
| 42 | + |
| 43 | +<resolution> |
| 44 | +<p> |
| 45 | +This wording is relative to <paper num="N4988"/>. |
| 46 | +</p> |
| 47 | + |
| 48 | +<ol> |
| 49 | +<li><p>Modify <sref ref="[container.adaptors.format]"/> as indicated:</p> |
| 50 | + |
| 51 | +<blockquote> |
| 52 | +<p> |
| 53 | +-1- For each of <tt>queue</tt>, <tt>priority_queue</tt>, and <tt>stack</tt>, the library provides the |
| 54 | +following <del>formatter</del> specialization<ins>s</ins> where <tt><i>adaptor-type</i></tt> is the |
| 55 | +name of the template: |
| 56 | +</p> |
| 57 | +<blockquote><pre> |
| 58 | +namespace std { |
| 59 | + template<class charT, class T, formattable<charT> Container, class... U> |
| 60 | + struct formatter<<i>adaptor-type</i><T, Container, U...>, charT> { |
| 61 | + […] |
| 62 | + }; |
| 63 | + |
| 64 | + <ins>template<class T, class Container, class... U></ins> |
| 65 | + <ins>constexpr bool enable_nonlocking_formatter_optimization<<i>adaptor-type</i><T, Container, U...>> =</ins> |
| 66 | + <ins>enable_nonlocking_formatter_optimization<T>;</ins> |
| 67 | +} |
| 68 | +</pre></blockquote> |
| 69 | +</blockquote> |
| 70 | +</li> |
| 71 | + |
| 72 | +</ol> |
| 73 | + |
| 74 | +</resolution> |
| 75 | + |
| 76 | +</issue> |
0 commit comments