Ignore:
Timestamp:
Aug 27, 2018, 4:40:34 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
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.
Message:

Merge branch 'master' into cleanup-dtors

File:
1 moved

Legend:

Unmodified
Added
Removed
  • tests/function-operator.c

    rf9feab8 r90152a4  
    99// Author           : Rob Schluntz
    1010// Created On       : Fri Aug 25 15:21:11 2017
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Fri Aug 25 15:31:29 2017
    13 // Update Count     : 2
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Aug  2 09:27:53 2018
     13// Update Count     : 8
    1414//
    1515
    16 #include <fstream>
    17 #include <stdlib>
     16#include <fstream.hfa>
     17#include <stdlib.hfa>
    1818
    1919#define length(array) (sizeof((array))/sizeof((array)[0]))
     
    3434forall(otype Tin, dtype Input | Iterator(Input, Tin), otype Tout, dtype Output | Iterator(Output, Tout) | Assignable(Tout, Tin))
    3535Output 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;
    4141}
    4242
     
    4444forall(otype Tin, dtype Input | Iterator(Input, Tin), otype Tout, dtype Output | Iterator(Output, Tout), otype FuncRet, dtype Func | { FuncRet ?()(Func *, Tin); } | Assignable(Tout, FuncRet))
    4545Output 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;
    5151}
    5252
     
    5454forall(dtype Iter, otype T | Iterator(Iter, T), otype Pred | { int ?()(Pred, T); })
    5555Iter 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;
    6161}
    6262
     
    6464forall(otype Generator, otype GenRet | { GenRet ?()(Generator &); }, dtype Iter, otype T| Iterator(Iter, T) | Assignable(T, GenRet))
    6565void 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        }
    7171}
    7272
     
    7878// TODO: abstract over os type with ostream trait; resolver is currently too slow for this to be reasonable, but it does work.
    7979struct os_wrapper {
    80   ofstream * out;
     80        ofstream * out;
    8181};
    8282
    8383// TODO: abstract over (os, T)
    8484os_wrapper ?=?(os_wrapper & wrapper, int x) {
    85   wrapper.out | x | endl;
    86   return wrapper;
     85        *wrapper.out | x | endl;
     86        return wrapper;
    8787}
    8888
    89 struct ostream_iterator {
    90   os_wrapper * out;
    91 };
     89        struct ostream_iterator {
     90                os_wrapper * out;
     91        };
    9292void ?{}(ostream_iterator & iter, ofstream * out) {
    93   iter.out = new(out);
     93        iter.out = new(out);
    9494}
    9595// no destructor, memory leak. This is necessary for this to work at the moment, since
     
    9898// implement Iterator
    9999os_wrapper & *?(ostream_iterator iter) {
    100   return *iter.out;
     100        return *iter.out;
    101101}
    102102ostream_iterator ++?(ostream_iterator & iter) {
    103   // nothing to do
    104   return iter;
     103        // nothing to do
     104        return iter;
    105105}
    106106int ?!=?(ostream_iterator i1, ostream_iterator i2) {
    107   return i1.out->out != i2.out->out;
     107        return i1.out->out != i2.out->out;
    108108}
    109109
     
    132132forall(otype Return, ttype Args)
    133133struct function {
    134   Return (*f)(Args);
     134        Return (*f)(Args);
    135135};
    136136// TODO: missing adapter in these functions
     
    148148
    149149        // copy for output
    150         ostream_iterator out_iter = { sout };
     150        ostream_iterator out_iter = { &sout };
    151151        copy(begin(x), end(x), out_iter);
    152152        copy(begin(y), end(y), out_iter);
     
    168168        transform(begin(x), end(x), begin(x), &times2);
    169169        copy(begin(x), end(x), out_iter);
     170
     171        // REMOVE WHEN ?* PROBLEM FIXED.
     172        delete(out_iter.out);
    170173}
    171174
Note: See TracChangeset for help on using the changeset viewer.