| title | unary_delegate (STL/CLR) | Microsoft Docs | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ms.custom | ||||||||||||||
| ms.date | 11/04/2016 | |||||||||||||
| ms.reviewer | ||||||||||||||
| ms.suite | ||||||||||||||
| ms.technology |
|
|||||||||||||
| ms.tgt_pltfrm | ||||||||||||||
| ms.topic | reference | |||||||||||||
| f1_keywords |
|
|||||||||||||
| dev_langs |
|
|||||||||||||
| helpviewer_keywords |
|
|||||||||||||
| ms.assetid | b3ee253c-98e8-466e-a272-505e47aed061 | |||||||||||||
| caps.latest.revision | 14 | |||||||||||||
| author | mikeblome | |||||||||||||
| ms.author | mblome | |||||||||||||
| manager | ghogen | |||||||||||||
| translation.priority.ht |
|
The genereic class describes a one-argument delegate. You use it specify a delegate in terms of its argument and return types.
generic<typename Arg,
typename Result>
delegate Result unary_delegate(Arg);
Arg
The type of the argument.
Result
The return type.
The genereic delegate describes a one-argument function.
Note that for:
unary_delegare<int, int> Fun1;
unary_delegare<int, int> Fun2;
the types Fun1 and Fun2 are synonyms, while for:
delegate int Fun1(int);
delegate int Fun2(int);
they are not the same type.
// cliext_unary_delegate.cpp
// compile with: /clr
#include <cliext/functional>
int hash_val(wchar_t val)
{
return ((val * 17 + 31) % 67);
}
typedef cliext::unary_delegate<wchar_t, int> Mydelegate;
int main()
{
Mydelegate^ myhash = gcnew Mydelegate(&hash_val);
System::Console::WriteLine("hash(L'a') = {0}", myhash(L'a'));
System::Console::WriteLine("hash(L'b') = {0}", myhash(L'b'));
return (0);
}
hash(L'a') = 5
hash(L'b') = 22
Header: <cliext/functional>
Namespace: cliext
binary_delegate (STL/CLR)
binary_delegate_noreturn (STL/CLR)
unary_delegate_noreturn (STL/CLR)