次の方法で共有


negate 構造体

引数に対して算術否定演算 (単項 operator-) を実行する定義済みの関数オブジェクト。

template<class Type = void>
   struct negate : public unary_function<Type, Type> 
   {
      Type operator()(
         const Type& Left
      ) const;
   };

// specialized transparent functor for unary operator-
template<>
   struct negate<void>
   {
      template<class Type>
      auto operator()(Type&& Left) const
         -> decltype(-std::forward<Type>(Left));
   };

パラメーター

  • Type
    指定または推論された型のオペランドを受け取る operator- をサポートする任意の型。

  • Left
    符号を反転されるオペランド。 特殊化されたテンプレートは、推論された型 Type の左辺値および右辺値参照引数の完全転送を行います。

戻り値

-Left. の結果。特殊化されたテンプレートは、結果の完全転送を行います。結果には単項 operator- によって返された型が含まれます。

使用例

// functional_negate.cpp
// compile with: /EHsc
#include <vector>
#include <functional>
#include <algorithm>
#include <iostream>

using namespace std;

int main( )
{
   vector <int> v1, v2 ( 8 );
   vector <int>::iterator Iter1, Iter2;
   
   int i;
   for ( i = -2 ; i <= 5 ; i++ )
   {
      v1.push_back( 5 * i );
   }

   cout << "The vector v1 = ( " ;
   for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ )
      cout << *Iter1 << " ";
   cout << ")" << endl;

   // Finding the element-wise negatives of the vector v1
   transform ( v1.begin( ),  v1.end( ), v2.begin( ), negate<int>( ) );

   cout << "The negated elements of the vector = ( " ;
   for ( Iter2 = v2.begin( ) ; Iter2 != v2.end( ) ; Iter2++ )
      cout << *Iter2 << " ";
   cout << ")" << endl;
}
  

必要条件

ヘッダー: <functional>

名前空間: std

参照

関連項目

C++ 標準ライブラリ内のスレッド セーフ

標準テンプレート ライブラリ