1 // functional stl/clr header
2 #ifndef _CLI_FUNCTIONAL_
3  #define _CLI_FUNCTIONAL_
4 #include <cliext/xutility>
5
6 namespace cliext {
7 //
8 // GENERICS DELEGATES
9 //
10
11 // GENERIC DELEGATE unary_delegate
12 //
13 generic<typename TArg,
14     typename TResult>
15     delegate TResult unary_delegate(TArg);
16
17 // GENERIC DELEGATE unary_delegate_noreturn
18 //
19 generic<typename TArg>
20     delegate void unary_delegate_noreturn(TArg);
21
22 //
23 // GENERIC DELEGATE binary_delegate
24 //
25 generic<typename TArg1,
26     typename TArg2,
27     typename TResult>
28     delegate TResult binary_delegate(TArg1, TArg2);
29
30 //
31 // GENERIC DELEGATE binary_delegate_noreturn
32 //
33 generic<typename TArg1,
34     typename TArg2>
35     delegate void binary_delegate_noreturn(TArg1, TArg2);
36
37 //
38 // TEMPLATE REF FUNCTORS
39 //
40
41 //
42 // TEMPLATE REF unary_function
43 //
44 template<typename _Arg_t,
45     typename _Result_t>
46     ref class unary_function
47     {    // defines typedefs for a unary function
48 public:
49     typedef _Arg_t argument_type;
50     typedef _Result_t result_type;
51     };
52
53 //
Lines 54 ... 1045 are skipped.
1046
1047     bool operator()(argument_type _Left, argument_type _Right)
1048         {    // do the operation
1049         return (function(_Left, _Right));
1050         }
1051
1052     operator delegate_type^()
1053         {    // convert function to delegate
1054         return (gcnew delegate_type(%function));
1055         }
1056
1057     static bool function(argument_type _Left, argument_type _Right)
1058         {    // do the operation
1059         return (_Mycomp->Compare(_Left, _Right) < 0);
1060         }
1061
1062 _STLCLR_FIELD_ACCESS:
1063     _Mycomp_t^ _Mycomp;    // the stored IComparer object
1064     };
1065
1066 //
1067 // TEMPLATE FUNCTION make_comparer_less
1068 //
1069 template<typename _Arg_t> inline
1070     comparer_less<_Arg_t,
1071         System::Collections::Generic::IComparer<_Arg_t> >^
1072     make_comparer_less(
1073         System::Collections::Generic::IComparer<_Arg_t>^ _Comp)
1074     {    // make comparer less from IComparer<T>
1075     typedef System::Collections::Generic::IComparer<_Arg_t> _Mycomp_t;
1076
1077     return (gcnew comparer_less<_Arg_t, _Mycomp_t>(_Comp));
1078     }
1079
1080 inline comparer_less<System::Object^, System::Collections::IComparer>^
1081     make_comparer_less(System::Collections::IComparer^ _Comp)
1082     {    // make comparer less from IComparer
1083     typedef System::Collections::IComparer _Mycomp_t;
1084
1085     return (gcnew comparer_less<System::Object^, _Mycomp_t>(_Comp));
1086     }
1087 }    // namespace cliext
1088 #endif // _CLI_FUNCTIONAL_
1089
1090 /*
1091  * Copyright (c) 2004-2007 by Dinkumware, Ltd.  ALL RIGHTS RESERVED.
1092  * Consult your license regarding permissions and restrictions.
1093 V5.03:0009 */
1094