binary_delegate (STL/CLR)
A classe genereic descreve um delegate de dois argumentos.Use-especificar um representante em termos de seus tipos de argumento e retornar.
generic<typename Arg1,
typename Arg2,
typename Result>
delegate Result binary_delegate(Arg1, Arg2);
Parâmetros
Arg1
O tipo do primeiro argumento.Arg2
O tipo do segundo argumento.Resultado
O tipo de retorno.
Comentários
O delegado genereic descreve uma função de dois argumentos.
Observe que para:
binary_delegate<int, int, int> Fun1;
binary_delegate<int, int, int> Fun2;
tipos de Fun1 e Fun2 são sinônimos, enquanto para:
delegate int Fun1(int, int);
delegate int Fun2(int, int);
eles não são do mesmo tipo.
Exemplo
// cliext_binary_delegate.cpp
// compile with: /clr
#include <cliext/functional>
bool key_compare(wchar_t left, wchar_t right)
{
return (left < right);
}
typedef cliext::binary_delegate<wchar_t, wchar_t, bool> Mydelegate;
int main()
{
Mydelegate^ kcomp = gcnew Mydelegate(&key_compare);
System::Console::WriteLine("compare(L'a', L'a') = {0}",
kcomp(L'a', L'a'));
System::Console::WriteLine("compare(L'a', L'b') = {0}",
kcomp(L'a', L'b'));
System::Console::WriteLine("compare(L'b', L'a') = {0}",
kcomp(L'b', L'a'));
System::Console::WriteLine();
return (0);
}
Requisitos
Cabeçalho: < cliext/funcional >
Namespace: cliext