std:: binary_negate
| 
           
           Défini dans l'en-tête
            
         
            
             <functional>
            
           
           | 
         ||
| 
           
           
            
             template
            
            
             <
            
            
             class
            
            Predicate
            
             >
            
             
         
             
              struct
             
             binary_negate
               | 
         (jusqu'à C++11) | |
| 
           
           
            
             template
            
            
             <
            
            
             class
            
            Predicate
            
             >
            
             
         struct binary_negate ;  | 
         
          
           (depuis C++11)
          
           (obsolète en C++17) (supprimé en C++20)  | 
        |
       
        std::binary_negate
       
       est une fonction objet enveloppe qui retourne le complément du prédicat binaire qu'elle contient.
      
       Le type de prédicat binaire doit définir deux types membres,
       
        first_argument_type
       
       et
       
        second_argument_type
       
       , qui sont convertibles vers les types de paramètres du prédicat. Les objets fonction obtenus à partir de
       
        
         std::owner_less
        
       
       ,
       
        
         std::ref
        
       
       ,
       
        
         std::cref
        
       
       ,
       
        
         std::plus
        
       
       ,
       
        
         std::minus
        
       
       ,
       
        
         std::multiplies
        
       
       ,
       
        
         std::divides
        
       
       ,
       
        
         std::modulus
        
       
       ,
       
        
         std::equal_to
        
       
       ,
       
        
         std::not_equal_to
        
       
       ,
       
        
         std::greater
        
       
       ,
       
        
         std::less
        
       
       ,
       
        
         std::greater_equal
        
       
       ,
       
        
         std::less_equal
        
       
       ,
       
        
         std::logical_not
        
       
       ,
       
        
         std::logical_or
        
       
       ,
       
        
         std::bit_and
        
       
       ,
       
        
         std::bit_or
        
       
       ,
       
        std::bit_xor
       
       ,
       
        
         std::mem_fn
        
       
       ,
       
        
         std::map::value_comp
        
       
       ,
       
        
         std::multimap::value_comp
        
       
       ,
       
        
         std::function
        
       
       , ou d'un appel à
       
        
         std::not2
        
       
       ont ces types définis, tout comme les objets fonction dérivés de l'obsolète
       
        
         std::binary_function
        
       
       .
      
       
        std::binary_negate
       
       objects are easily constructed with helper function
       
        
         std::not2
        
       
       .
      
         Table des matières | 
       
Types membres
| Type | Définition | 
         
          first_argument_type
         
         | 
        Predicate :: first_argument_type | 
         
          second_argument_type
         
         | 
        Predicate :: second_argument_type | 
         
          result_type
         
         | 
        bool | 
Fonctions membres
| 
          
           
            
             (constructor)
            
           
           
          | 
        
         construit un nouvel objet binary_negate avec le prédicat fourni
          (fonction membre publique)  | 
       
| 
          
           
            
             operator()
            
           
           
          | 
        
         retourne le complément logique du résultat d'un appel au prédicat stocké
          (fonction membre publique)  | 
       
std::binary_negate:: binary_negate
| 
            
            
             
              explicit
             
             binary_negate
             
              (
             
             Predicate
             
              const
             
             
              &
             
             pred
             
              )
             
             
              ;
             
            
            
           | 
          (jusqu'à C++14) | |
| 
            
            
             
              constexpr
             
             
              explicit
             
             binary_negate
             
              (
             
             Predicate
             
              const
             
             
              &
             
             pred
             
              )
             
             
              ;
             
            
            
           | 
          (depuis C++14) | |
        Construit un objet fonction
        
         std::binary_negate
        
        avec le prédicat stocké
        
         
          pred
         
        
        .
       
Paramètres
| pred | - | objet fonction prédicat | 
std::binary_negate:: operator()
| 
            
            
             
              bool
             
             operator
             
              (
             
             
              )
             
             
              (
             
             first_argument_type
             
              const
             
             
              &
             
             x,
              
          second_argument_type const & y ) const ;  | 
          (jusqu'en C++14) | |
| 
            
            
             
              constexpr
             
             
              bool
             
             operator
             
              (
             
             
              )
             
             
              (
             
             first_argument_type
             
              const
             
             
              &
             
             x,
              
          second_argument_type const & y ) const ;  | 
          (depuis C++14) | |
Retourne le complément logique du résultat de l'appel à pred ( x, y ) .
Paramètres
| x | - | premier argument à transmettre au prédicat | 
| y | - | second argument à transmettre au prédicat | 
Valeur de retour
Le complément logique du résultat de l'appel à pred ( x, y ) .
Exemple
#include <algorithm> #include <cstddef> #include <functional> #include <iostream> #include <vector> struct same : std::binary_function<int, int, bool> { bool operator()(int a, int b) const { return a == b; } }; int main() { std::vector<int> v1; for (int i = 0; i < 7; ++i) v1.push_back(i); std::vector<int> v2(v1.size()); std::reverse_copy(v1.begin(), v1.end(), v2.begin()); std::vector<bool> v3(v1.size()); std::binary_negate<same> not_same((same())); // Solution C++11 : // std::function<bool (int, int)> not_same = // [](int x, int y) -> bool { return !same()(x, y); }; std::transform(v1.begin(), v1.end(), v2.begin(), v3.begin(), not_same); std::cout.setf(std::ios_base::boolalpha); for (std::size_t i = 0; i != v1.size(); ++i) std::cout << v1[i] << " != " << v2[i] << " : " << v3[i] << '\n'; }
Sortie :
0 != 6 : true 1 != 5 : true 2 != 4 : true 3 != 3 : false 4 != 2 : true 5 != 1 : true 6 != 0 : true
Voir aussi
| 
          
           
            
             
              (déprécié en C++11)
             
            
            
             
              (supprimé en C++17)
             
            
           
           
          | 
        
         classe de base de fonction binaire compatible avec les adaptateurs
          (modèle de classe)  | 
       
| 
          
           
            
             
              (C++11)
             
            
           
           
          | 
        
         wrapper copiable de tout objet appelable constructible par copie
          (modèle de classe)  | 
       
| 
          
           
            
             
              (C++23)
             
            
           
           
          | 
        
         wrapper non copiable de tout objet appelable prenant en charge les qualificateurs dans une signature d'appel donnée
          (modèle de classe)  | 
       
| 
          
           
            
             
              (déprécié en C++17)
             
            
            
             
              (supprimé en C++20)
             
            
           
           
          | 
        
         construit un objet
         
          
           std::binary_negate
          
         
         personnalisé
          (modèle de fonction)  | 
       
| 
          
           
            
             
              (déprécié en C++11)
             
            
            
             
              (supprimé en C++17)
             
            
           
           
          | 
        
         crée un wrapper d'objet fonction compatible avec les adaptateurs à partir d'un pointeur de fonction
          (modèle de fonction)  | 
       
| 
          
           
            
             
              (déprécié en C++17)
             
            
            
             
              (supprimé en C++20)
             
            
           
           
          | 
        
         objet fonction wrapper retournant le complément du prédicat unaire qu'il contient
          (modèle de classe)  |