| [86bd7c1f] | 1 | // | 
|---|
|  | 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo | 
|---|
|  | 3 | // | 
|---|
|  | 4 | // The contents of this file are covered under the licence agreement in the | 
|---|
|  | 5 | // file "LICENCE" distributed with Cforall. | 
|---|
|  | 6 | // | 
|---|
| [1ad1c99e] | 7 | // array.h -- | 
|---|
| [86bd7c1f] | 8 | // | 
|---|
|  | 9 | // Author           : Richard C. Bilson | 
|---|
|  | 10 | // Created On       : Wed May 27 17:56:53 2015 | 
|---|
| [1ad1c99e] | 11 | // Last Modified By : Rob Schluntz | 
|---|
|  | 12 | // Last Modified On : Wed Apr 27 17:26:04 2016 | 
|---|
| [4040425] | 13 | // Update Count     : 5 | 
|---|
| [86bd7c1f] | 14 | // | 
|---|
|  | 15 |  | 
|---|
| [51b73452] | 16 | #ifndef ARRAY_H | 
|---|
|  | 17 | #define ARRAY_H | 
|---|
|  | 18 |  | 
|---|
| [d3b7937] | 19 | //#include <iterator> | 
|---|
| [51b73452] | 20 |  | 
|---|
| [134b86a] | 21 | // An array has contiguous elements accessible in any order using integer indicies. The first | 
|---|
|  | 22 | // element has index 0. | 
|---|
| [4040425] | 23 | trait array( otype array_type, otype elt_type ) { | 
|---|
| [86bd7c1f] | 24 | lvalue elt_type ?[?]( array_type, int ); | 
|---|
| [51b73452] | 25 | }; | 
|---|
|  | 26 |  | 
|---|
| [134b86a] | 27 | // A bounded array is an array that carries its maximum index with it. | 
|---|
| [1ad1c99e] | 28 | trait bounded_array( otype array_type, otype elt_type | array( array_type *, elt_type ) ) { | 
|---|
|  | 29 | int last( array_type * ); | 
|---|
| [51b73452] | 30 | }; | 
|---|
|  | 31 |  | 
|---|
|  | 32 | // implement iterator_for | 
|---|
|  | 33 |  | 
|---|
|  | 34 | typedef int array_iterator; | 
|---|
| [134b86a] | 35 |  | 
|---|
| [4040425] | 36 | /// forall( otype array_type, elt_type | bounded_array( array_type, elt_type ) ) | 
|---|
| [51b73452] | 37 | /// [ array_iterator begin, array_iterator end ] get_iterators( array_type ); | 
|---|
| [134b86a] | 38 |  | 
|---|
|  | 39 |  | 
|---|
|  | 40 | // A bounded array can be iterated over by using a pointer to the element type. These functions | 
|---|
|  | 41 | // return iterators corresponding to the first element and the one-past-the-end element, STL-style. | 
|---|
| [4040425] | 42 | forall( otype array_type, otype elt_type | bounded_array( array_type, elt_type ) ) | 
|---|
| [1ad1c99e] | 43 | elt_type * begin( array_type * array ); | 
|---|
| [134b86a] | 44 |  | 
|---|
| [1ad1c99e] | 45 | // The end iterator should point one past the last element. | 
|---|
| [4040425] | 46 | forall( otype array_type, otype elt_type | bounded_array( array_type, elt_type ) ) | 
|---|
| [1ad1c99e] | 47 | elt_type * end( array_type * array ); | 
|---|
| [51b73452] | 48 |  | 
|---|
| [134b86a] | 49 | #endif // ARRAY_H | 
|---|
| [86bd7c1f] | 50 |  | 
|---|
|  | 51 | // Local Variables: // | 
|---|
|  | 52 | // tab-width: 4 // | 
|---|
|  | 53 | // compile-command: "cfa array.c" // | 
|---|
|  | 54 | // End: // | 
|---|