Changeset 8e4aa05 for tests/function-operator.cfa
- Timestamp:
- Mar 4, 2021, 7:40:25 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 77d601f
- Parents:
- 342af53 (diff), a5040fe (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/function-operator.cfa
r342af53 r8e4aa05 22 22 23 23 // STL-like Algorithms 24 trait Assignable( dtype T, dtype U) { T ?=?(T &, U); };25 trait Copyable( dtype T) { void ?{}(T &, T); };26 trait Destructable( dtype T) { void ^?{}(T &); };24 trait Assignable(T &, U &) { T ?=?(T &, U); }; 25 trait Copyable(T &) { void ?{}(T &, T); }; 26 trait Destructable(T &) { void ^?{}(T &); }; 27 27 28 trait Iterator( dtype iter | sized(iter) | Copyable(iter) | Destructable(iter), otypeT) {28 trait Iterator(iter & | sized(iter) | Copyable(iter) | Destructable(iter), T) { 29 29 T & *?(iter); 30 30 iter ++?(iter &); … … 32 32 }; 33 33 34 forall( otype Tin, dtype Input | Iterator(Input, Tin), otype Tout, dtype Output| Iterator(Output, Tout) | Assignable(Tout, Tin))34 forall(Tin, Input & | Iterator(Input, Tin), Tout, Output & | Iterator(Output, Tout) | Assignable(Tout, Tin)) 35 35 Output copy(Input first, Input last, Output result) { 36 36 while (first != last) { … … 42 42 43 43 // test ?()(T *, ...) -- ?() with function call-by-pointer 44 forall( otype Tin, dtype Input | Iterator(Input, Tin), otype Tout, dtype Output | Iterator(Output, Tout), otype FuncRet, dtype Func| { FuncRet ?()(Func *, Tin); } | Assignable(Tout, FuncRet))44 forall(Tin, Input & | Iterator(Input, Tin), Tout, Output & | Iterator(Output, Tout), FuncRet, Func & | { FuncRet ?()(Func *, Tin); } | Assignable(Tout, FuncRet)) 45 45 Output transform (Input first, Input last, Output result, Func * op) { 46 46 while (first != last) { … … 52 52 53 53 // test ?()(T, ...) -- ?() with function call-by-value 54 forall( dtype Iter, otype T | Iterator(Iter, T), otypePred | { int ?()(Pred, T); })54 forall(Iter &, T | Iterator(Iter, T), Pred | { int ?()(Pred, T); }) 55 55 Iter find_if (Iter first, Iter last, Pred pred) { 56 56 while (first != last) { … … 62 62 63 63 // test ?()(T, ...) -- ?() with function call-by-reference 64 forall( otype Generator, otype GenRet | { GenRet ?()(Generator &); }, dtype Iter, otypeT | Iterator(Iter, T) | Assignable(T, GenRet))64 forall(Generator, GenRet | { GenRet ?()(Generator &); }, Iter &, T | Iterator(Iter, T) | Assignable(T, GenRet)) 65 65 void generate(Iter first, Iter last, Generator & gen) { 66 66 int i = 0; … … 108 108 } 109 109 110 forall( otypeT | { int ?==?(T, T); })110 forall(T | { int ?==?(T, T); }) 111 111 struct Equals { 112 112 T val; 113 113 }; 114 114 115 forall( otypeT | { int ?==?(T, T); })115 forall(T | { int ?==?(T, T); }) 116 116 int ?()(Equals(T) eq, T x) { 117 117 return eq.val == x; 118 118 } 119 119 120 forall( otypeT | { T ?*?(T, T); })120 forall(T | { T ?*?(T, T); }) 121 121 struct Multiply { 122 122 T val; 123 123 }; 124 124 125 forall( otypeT | { T ?*?(T, T); })125 forall(T | { T ?*?(T, T); }) 126 126 T ?()(Multiply(T) * mult, T x) { 127 127 return mult->val * x; … … 130 130 // TODO: generalize to ttype return; doesn't work yet 131 131 // like std::function 132 forall( otype Return, ttype Args)132 forall(Return, Args...) 133 133 struct function { 134 134 Return (*f)(Args);
Note:
See TracChangeset
for help on using the changeset viewer.