Espaços nominais
Variantes
Acções

std::ptr_fun

Da cppreference.com
< cpp‎ | utility‎ | functional

 
 
Biblioteca de utilitários
Digite apoio (basic types, RTTI, type traits)
Gerenciamento de memória dinâmica
De tratamento de erros
Utilidades do programa
Variadic funções
Data e hora
Objetos de função
(C++11)
Os operadores relacionais
Original:
Relational operators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
rel_ops::operator!=
rel_ops::operator>
rel_ops::operator<=
rel_ops::operator>=
Pares e tuplas
Original:
Pairs and tuples
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
Troque, avançar e avançar
Original:
Swap, forward and move
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
(C++11)
(C++11)
 
Objetos de função


Invólucros de função
Original:
Function wrappers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
(C++11)
Ligar
Original:
Bind
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
Invólucros de referência
Original:
Reference wrappers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)(C++11)
Invólucros operador
Original:
Operator wrappers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Negadores
Original:
Negators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Obsoleta ligantes e adaptadores
Original:
Deprecated binders and adaptors
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(obsoleta)
(obsoleta)
ptr_fun
(obsoleta)
(obsoleta)
(obsoleta)(obsoleta)(obsoleta)(obsoleta)
(obsoleta)
(obsoleta)(obsoleta)
(obsoleta)(obsoleta)
 
template< class Arg, class Result >

std::pointer_to_unary_function<Arg,Result>

    ptr_fun( Result (*f)(Arg) );
(1) (obsoleta)
template< class Arg1, class Arg2, class Result >

std::pointer_to_binary_function<Arg1,Arg2,Result>

    ptr_fun( Result (*f)(Arg1, Arg2) );
(2) (obsoleta)

Creates a function wrapper object (either std::pointer_to_unary_function or std::pointer_to_binary_function), deducing the target type from the template arguments.

1)
Efetivamente chama std::pointer_to_unary_function<Arg,Result>(f).
Original:
Effectively calls std::pointer_to_unary_function<Arg,Result>(f).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
2)
Efetivamente chama std::pointer_to_binary_function<Arg1,Arg2,Result>(f).
Original:
Effectively calls std::pointer_to_binary_function<Arg1,Arg2,Result>(f).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

This function and the related types are deprecated as of C++11 in favor of the more general std::function and std::ref, both of which create callable adapter-compatible function objects from plain functions.

Índice

[editar] Parâmetros

f - pointer to a function to create a wrapper for

[editar] Valor de retorno

A function object wrapping f.

[editar] Exceções

(Nenhum)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Exemplo

#include <string>
#include <iostream>
#include <algorithm>
#include <functional>
bool isvowel(char c)
{
    return std::string("aeoiuAEIOU").find(c) != std::string::npos;
}
int main()
{
    std::string s = "Hello, world!";
    std::copy_if(s.begin(), s.end(), std::ostreambuf_iterator<char>(std::cout),
                 std::not1(std::ptr_fun(isvowel)));
// C++11 alternatives: 
//               std::not1(std::ref(isvowel)));
//               std::not1(std::function<bool(char)>(isvowel)));
 
}

Saída:

Hll, wrld!