Nota:
El acceso a esta página requiere autorización. Puede intentar iniciar sesión o cambiar directorios.
El acceso a esta página requiere autorización. Puede intentar cambiar los directorios.
Struct base vacío que define los tipos que pueden ser heredados por las clases derivadas que proporciona un objeto singular de la función.
template<class Arg, class Result>
struct unary_function {
typedef Arg argument_type;
typedef Result result_type;
};
Comentarios
Struct de plantilla sirve como base para las clases que definen una función miembro const de result_typeoperator() de formulario (argument_type&const).
Todas estas funciones unarios derivadas pueden hacer referencia al único tipo de argumento como argument_type y su tipo de valor devuelto como result_type.
Ejemplo
// functional_unary_function.cpp
// compile with: /EHsc
#include <vector>
#include <functional>
#include <algorithm>
#include <iostream>
using namespace std;
// Creation of a user-defined function object
// that inherits from the unary_function base class
class greaterthan10: unary_function<int, bool>
{
public:
result_type operator()(argument_type i)
{
return (result_type)(i > 10);
}
};
int main()
{
vector<int> v1;
vector<int>::iterator Iter;
int i;
for (i = 0; i <= 5; 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;
result1 = count_if(v1.begin(), v1.end(), greaterthan10());
cout << "The number of elements in v1 greater than 10 is: "
<< result1 << "." << endl;
}
Requisitos
encabezado: <funcional>
espacio de nombres: std