binary_delegate (STL/CLR)
La clase genereic describe un delegado de dos- argumento. Se utiliza especifica un delegado en términos de argumento y tipos de valor devuelto.
generic<typename Arg1,
typename Arg2,
typename Result>
delegate Result binary_delegate(Arg1, Arg2);
Parámetros
Arg1
El tipo del primer argumento.Arg2
El tipo del segundo argumento.Resultado
El tipo de valor devuelto.
Comentarios
El delegado genereic describe una función de dos- argumento.
Observe que para:
binary_delegate<int, int, int> Fun1;
binary_delegate<int, int, int> Fun2;
los tipos Fun1 y Fun2 son sinónimos, mientras que para:
delegate int Fun1(int, int);
delegate int Fun2(int, int);
no son el mismo tipo.
Ejemplo
// 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
cliext <deEncabezado: /funcional>
cliext deEspacio de nombres: