<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 347: locale::category and bitmask requirements</title>
<meta property="og:title" content="Issue 347: locale::category and bitmask requirements">
<meta property="og:description" content="C++ library issue. Status: CD1">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue347.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#CD1">CD1</a> status.</em></p>
<h3 id="347"><a href="lwg-defects.html#347">347</a>. locale::category and bitmask requirements</h3>
<p><b>Section:</b> 28.3.3.1.2.1 <a href="https://wg21.link/locale.category">[locale.category]</a> <b>Status:</b> <a href="lwg-active.html#CD1">CD1</a>
 <b>Submitter:</b> P.J. Plauger, Nathan Myers <b>Opened:</b> 2001-10-23 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#locale.category">issues</a> in [locale.category].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#CD1">CD1</a> status.</p>
<p><b>Discussion:</b></p>
<p>
In 28.3.3.1.2.1 <a href="https://wg21.link/locale.category">[locale.category]</a> paragraph 1, the category members
are described as bitmask elements.  In fact, the bitmask requirements
in 16.3.3.3.3 <a href="https://wg21.link/bitmask.types">[bitmask.types]</a> don't seem quite right: <code>none</code>
and <code>all</code> are bitmask constants, not bitmask elements.</p>

<p>In particular, the requirements for <code>none</code> interact poorly
with the requirement that the LC_* constants from the C library must
be recognizable as C++ locale category constants.  LC_* values should
not be mixed with these values to make category values.</p>

<p>We have two options for the proposed resolution.  Informally:
option 1 removes the requirement that LC_* values be recognized as
category arguments.  Option 2 changes the category type so that this
requirement is implementable, by allowing <code>none</code> to be some
value such as 0x1000 instead of 0.</p>

<p>Nathan writes: "I believe my proposed resolution [Option 2] merely
re-expresses the status quo more clearly, without introducing any
changes beyond resolving the DR.</p>



<p id="res-347"><b>Proposed resolution:</b></p>
<p>Replace the first two paragraphs of 28.3.3.1.2 <a href="https://wg21.link/locale.types">[locale.types]</a> with:</p>
<blockquote>
<pre>
    typedef int category;
</pre>

<p>Valid category values include the <code>locale</code> member bitmask
elements <code>collate</code>, <code>ctype</code>, <code>monetary</code>,
<code>numeric</code>, <code>time</code>, and <code>messages</code>, each of which
represents a single locale category. In addition, <code>locale</code> member
bitmask constant <code>none</code> is defined as zero and represents no
category. And locale member bitmask constant <code>all</code> is defined such that
the expression</p>
<pre>
    (collate | ctype | monetary | numeric | time | messages | all) == all
</pre>
<p>
is <code>true</code>, and represents the union of all categories.  Further
the expression <code>(X | Y)</code>, where <code>X</code> and <code>Y</code> each
represent a single category, represents the union of the two
categories.
</p>

<p>
<code>locale</code> member functions expecting a <code>category</code>
argument require one of the <code>category</code> values defined above, or
the union of two or more such values. Such a <code>category</code>
argument identifies a set of locale categories. Each locale category,
in turn, identifies a set of locale facets, including at least those
shown in Table 51:
</p>
</blockquote>
<p><i>[Cura&ccedil;ao: need input from locale experts.]</i></p>




<p><b>Rationale:</b></p>

<p>The LWG considered, and rejected, an alternate proposal (described
  as "Option 2" in the discussion).  The main reason for rejecting it
  was that library implementors were concerened about implementation
  difficult, given that getting a C++ library to work smoothly with a
  separately written C library is already a delicate business.  Some
  library implementers were also concerned about the issue of adding
  extra locale categories.</p>

<blockquote>
<p><b>Option 2:</b> <br/>
Replace the first paragraph of 28.3.3.1.2 <a href="https://wg21.link/locale.types">[locale.types]</a> with:</p>
<blockquote>
<p>
Valid category values include the enumerated values.  In addition, the
result of applying commutative operators | and &amp; to any two valid 
values is valid, and results in the setwise union and intersection, 
respectively, of the argument categories.  The values <code>all</code> and 
<code>none</code> are defined such that for any valid value <code>cat</code>, the
expressions <code>(cat | all == all)</code>, <code>(cat &amp; all == cat)</code>,
<code>(cat | none == cat)</code> and <code>(cat &amp; none == none)</code> are 
true.  For non-equal values <code>cat1</code> and <code>cat2</code> of the
remaining enumerated values, <code>(cat1 &amp; cat2 == none)</code> is true.
For any valid categories <code>cat1</code> and <code>cat2</code>, the result
of <code>(cat1 &amp; ~cat2)</code> is valid, and equals the setwise union of 
those categories found in <code>cat1</code> but not found in <code>cat2</code>.
[Footnote: it is not required that <code>all</code> equal the setwise union
of the other enumerated values; implementations may add extra categories.]
</p>
</blockquote>
</blockquote>





</body>
</html>
