共用方式為


not1 Function

傳回一個一元運算子的述詞的補充方法。

template<class UnaryPredicate>
   unary_negate<UnaryPredicate> not1(
      const UnaryPredicate& _Pred
   );

參數

  • _Pred
    要變成相反值的一元的述詞。

傳回值

是完整的一元負述詞的一元的述詞。

備註

如果 unary_negate 從一個一元運算子的述詞 Pred(x) 建構,則它會傳回 !Pred(x)。

範例

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

using namespace std;

int main()
{
    vector<int> v1;
    vector<int>::iterator Iter;

    int i;
    for (i = 0; i <= 7; i++)
    {
        v1.push_back(5 * i);
    }

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

    vector<int>::iterator::difference_type result1;
    // Count the elements greater than 10
    result1 = count_if(v1.begin(), v1.end(), bind2nd(greater<int>(), 10));
    cout << "The number of elements in v1 greater than 10 is: "
         << result1 << "." << endl;

    vector<int>::iterator::difference_type result2;
    // Use the negator to count the elements less than or equal to 10
    result2 = count_if(v1.begin(), v1.end(),
        not1(bind2nd(greater<int>(), 10)));

    cout << "The number of elements in v1 not greater than 10 is: "
         << result2 << "." << endl;
}
  
  

需求

標題: <functional>

命名空間: std

請參閱

參考

標準樣板程式庫