C++14 のconstexpr対応

N3749 Constexpr Library Additions: functional


C++14では、ヘッダで定義される関数オブジェクトがconstexprに対応します。
たとえば、2つの値のどちらが小さいか比較を行うstd::less関数オブジェクトの場合、以下のように関数呼び出し演算子にconstexprが付きます。

template <class T>
struct less {
    typedef T first_argument_type;
    typedef T second_argument_type;
    typedef bool result_type;

    constexpr bool operator()(const T& x, const T& y) const { return x < y; }
};

以下が、constexpr対応する関数オブジェクトの一覧です:


算術演算関数オブジェクト

  • plus
  • minus
  • multiplies
  • divides
  • modulus
  • negate


比較演算関数オブジェクト

  • equal_to
  • not_equal_to
  • greater
  • less
  • greater_equal
  • less_equal


論理演算関数オブジェクト

  • logical_and
  • logical_or
  • logical_not


ビット演算関数オブジェクト

  • bit_and
  • bit_or
  • bit_xor
  • bit_not


論理反転関数オブジェクト

  • unary_negate
  • not1
  • binary_negate
  • not2