Title
Missing Bitwise Operations
Status
cd1
Section
[function.objects]
Submitter
Beman Dawes

Created on 2007-04-02.00:00:00 last changed 164 months ago

Messages

Date: 2010-10-21.18:28:33

Proposed resolution:

To [function.objects], Function objects, paragraph 2, add to the header <functional> synopsis:

template <class T> struct bit_and;
template <class T> struct bit_or;
template <class T> struct bit_xor;

At a location in clause 20 to be determined by the Project Editor, add:

The library provides basic function object classes for all of the bitwise operators in the language ([expr.bit.and], [expr.or], [exp.xor]).

template <class T> struct bit_and : binary_function<T,T,T> {
  T operator()(const T& x , const T& y ) const;
};

operator() returns x & y .

template <class T> struct bit_or : binary_function<T,T,T> {
  T operator()(const T& x , const T& y ) const;
};

operator() returns x | y .

template <class T> struct bit_xor : binary_function<T,T,T> {
  T operator()(const T& x , const T& y ) const;
};

operator() returns x ^ y .

Date: 2007-04-02.00:00:00

Section [function.objects] provides function objects 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 "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."

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: "Boost will also add ... (|, &, ^) in 1.35.0, because we need those function objects to represent various parallel collective operations (reductions, prefix reductions, etc.) in the new Message Passing Interface (MPI) library."

Because the bitwise operators have the strongest use cases, the proposed resolution is limited to them.

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg3360
2007-04-02 00:00:00admincreate