Changeset 90152a4 for tests/function-operator.c
- Timestamp:
- Aug 27, 2018, 4:40:34 PM (7 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- b7c89aa
- Parents:
- f9feab8 (diff), 305581d (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 moved
-
tests/function-operator.c (moved) (moved from src/tests/function-operator.c ) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tests/function-operator.c
rf9feab8 r90152a4 9 9 // Author : Rob Schluntz 10 10 // Created On : Fri Aug 25 15:21:11 2017 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Fri Aug 25 15:31:29 201713 // Update Count : 211 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 2 09:27:53 2018 13 // Update Count : 8 14 14 // 15 15 16 #include <fstream >17 #include <stdlib >16 #include <fstream.hfa> 17 #include <stdlib.hfa> 18 18 19 19 #define length(array) (sizeof((array))/sizeof((array)[0])) … … 34 34 forall(otype Tin, dtype Input | Iterator(Input, Tin), otype Tout, dtype Output | Iterator(Output, Tout) | Assignable(Tout, Tin)) 35 35 Output copy(Input first, Input last, Output result) { 36 while (first != last) {37 *result = *first;38 ++result; ++first;39 }40 return result;36 while (first != last) { 37 *result = *first; 38 ++result; ++first; 39 } 40 return result; 41 41 } 42 42 … … 44 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)) 45 45 Output transform (Input first, Input last, Output result, Func * op) { 46 while (first != last) {47 *result = op(*first);48 ++result; ++first;49 }50 return result;46 while (first != last) { 47 *result = op(*first); 48 ++result; ++first; 49 } 50 return result; 51 51 } 52 52 … … 54 54 forall(dtype Iter, otype T | Iterator(Iter, T), otype Pred | { int ?()(Pred, T); }) 55 55 Iter find_if (Iter first, Iter last, Pred pred) { 56 while (first != last) {57 if (pred(*first)) return first;58 ++first;59 }60 return last;56 while (first != last) { 57 if (pred(*first)) return first; 58 ++first; 59 } 60 return last; 61 61 } 62 62 … … 64 64 forall(otype Generator, otype GenRet | { GenRet ?()(Generator &); }, dtype Iter, otype T| Iterator(Iter, T) | Assignable(T, GenRet)) 65 65 void generate(Iter first, Iter last, Generator & gen) { 66 int i = 0;67 while (first != last) {68 *first = gen();69 ++first;70 }66 int i = 0; 67 while (first != last) { 68 *first = gen(); 69 ++first; 70 } 71 71 } 72 72 … … 78 78 // TODO: abstract over os type with ostream trait; resolver is currently too slow for this to be reasonable, but it does work. 79 79 struct os_wrapper { 80 ofstream * out;80 ofstream * out; 81 81 }; 82 82 83 83 // TODO: abstract over (os, T) 84 84 os_wrapper ?=?(os_wrapper & wrapper, int x) { 85 wrapper.out | x | endl;86 return wrapper;85 *wrapper.out | x | endl; 86 return wrapper; 87 87 } 88 88 89 struct ostream_iterator {90 os_wrapper * out;91 };89 struct ostream_iterator { 90 os_wrapper * out; 91 }; 92 92 void ?{}(ostream_iterator & iter, ofstream * out) { 93 iter.out = new(out);93 iter.out = new(out); 94 94 } 95 95 // no destructor, memory leak. This is necessary for this to work at the moment, since … … 98 98 // implement Iterator 99 99 os_wrapper & *?(ostream_iterator iter) { 100 return *iter.out;100 return *iter.out; 101 101 } 102 102 ostream_iterator ++?(ostream_iterator & iter) { 103 // nothing to do104 return iter;103 // nothing to do 104 return iter; 105 105 } 106 106 int ?!=?(ostream_iterator i1, ostream_iterator i2) { 107 return i1.out->out != i2.out->out;107 return i1.out->out != i2.out->out; 108 108 } 109 109 … … 132 132 forall(otype Return, ttype Args) 133 133 struct function { 134 Return (*f)(Args);134 Return (*f)(Args); 135 135 }; 136 136 // TODO: missing adapter in these functions … … 148 148 149 149 // copy for output 150 ostream_iterator out_iter = { sout };150 ostream_iterator out_iter = { &sout }; 151 151 copy(begin(x), end(x), out_iter); 152 152 copy(begin(y), end(y), out_iter); … … 168 168 transform(begin(x), end(x), begin(x), ×2); 169 169 copy(begin(x), end(x), out_iter); 170 171 // REMOVE WHEN ?* PROBLEM FIXED. 172 delete(out_iter.out); 170 173 } 171 174
Note:
See TracChangeset
for help on using the changeset viewer.