<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 660: Missing Bitwise Operations</title>
<meta property="og:title" content="Issue 660: Missing Bitwise Operations">
<meta property="og:description" content="C++ library issue. Status: CD1">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue660.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="660"><a href="lwg-defects.html#660">660</a>. Missing Bitwise Operations</h3>
<p><b>Section:</b> 22.10 <a href="https://wg21.link/function.objects">[function.objects]</a> <b>Status:</b> <a href="lwg-active.html#CD1">CD1</a>
 <b>Submitter:</b> Beman Dawes <b>Opened:</b> 2007-04-02 <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#function.objects">issues</a> in [function.objects].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#CD1">CD1</a> status.</p>
<p><b>Discussion:</b></p>
<p>Section 22.10 <a href="https://wg21.link/function.objects">[function.objects]</a> provides <em>function objects</em> for some unary and binary 
operations, but others are missing. In a LWG reflector discussion, beginning 
with c++std-lib-18078, pros and cons of adding some of the missing operations 
were discussed. Bjarne Stroustrup commented &quot;Why standardize what isn't used? 
Yes, I see the chicken and egg problems here, but it would be nice to see a 
couple of genuine uses before making additions.&quot;</p>
<p>A number of libraries, including Rogue Wave, GNU, Adobe ASL, and Boost, have 
already added these functions, either publicly or for internal use. For example, 
Doug Gregor commented: &quot;Boost will also add ... (|, &amp;, ^) in 1.35.0, because we 
need those <em>function objects</em> to represent various parallel 
collective operations (reductions, prefix reductions, etc.) in the new Message 
Passing Interface (MPI) library.&quot;</p>
<p>Because the bitwise operators have the strongest use cases, the proposed 
resolution is limited to them.</p>


<p id="res-660"><b>Proposed resolution:</b></p>
<p>To 22.10 <a href="https://wg21.link/function.objects">[function.objects]</a>, Function objects, paragraph 2, add to the header 
&lt;functional&gt; synopsis:</p>
<blockquote>
  <pre>template &lt;class T&gt; struct bit_and;
template &lt;class T&gt; struct bit_or;
template &lt;class T&gt; struct bit_xor;</pre>
</blockquote>
<p>At a location in clause 20 to be determined by the Project Editor, add:</p>
<blockquote>
  <p>The library provides basic function object classes for all of the bitwise 
  operators in the language ([expr.bit.and], [expr.or], [exp.xor]).</p>
  <pre>template &lt;class T&gt; struct bit_and : binary_function&lt;T,T,T&gt; {
  T operator()(const T&amp; x , const T&amp; y ) const;
};</pre>
  <blockquote>
    <p><code>operator()</code> returns<code> x &amp; y</code> .</p>
  </blockquote>
  <pre>template &lt;class T&gt; struct bit_or : binary_function&lt;T,T,T&gt; {
  T operator()(const T&amp; x , const T&amp; y ) const;
};</pre>
  <blockquote>
    <p><code>operator()</code> returns <code>x | y</code> .</p>
  </blockquote>
  <pre>template &lt;class T&gt; struct bit_xor : binary_function&lt;T,T,T&gt; {
  T operator()(const T&amp; x , const T&amp; y ) const;
};</pre>
  <blockquote>
    <p><code>operator()</code> returns <code>x ^ y</code> .</p>
  </blockquote>
</blockquote>





</body>
</html>
