| 30 | | * This function unpacks the bundle while applying the specified numeric operation. Parameter `op` specifies a binary operation. For each ''i'' in 0..''count''-1, the operation is applied to the ''i''-th element of `buf` and the ''i''-th element of the bundle, and the result replaces the ''i''-th element of `buf`. Parameter `count` is the number of elements in the bundle; `buf` should point to a region of memory with at least `count` elements. The elements should all have the same numeric type. |
| | 30 | * This function unpacks the bundle while applying the specified numeric operation. Parameter `op` specifies a binary operation. For each ''i'' in 0..''count''-1, the operation is applied to the ''i''-th element of `buf` and the ''i''-th element of the bundle, and the result is stored in the ''i''-th position of `result`. Parameter `count` is the number of elements in the bundle; `buf` and `result` should each point to a region of memory capable of holding at least `count` elements. |
| | 31 | |
| | 32 | === Example |
| | 33 | {{{ |
| | 34 | #include <bundle.cvh> |
| | 35 | int main() { |
| | 36 | int n = 10; |
| | 37 | int a[n], b[n], c[n]; |
| | 38 | for (int i=0; i<n; i++) a[i] = i; |
| | 39 | $bundle bun = $bundle_pack(a, n*sizeof(int)); |
| | 40 | $assert($bundle_size(bun) == n*sizeof(int)); |
| | 41 | $bundle_unpack(bun, b); |
| | 42 | $assert($forall (int i: 0..n-1) b[i]==a[i]); |
| | 43 | $bundle_unpack_apply(bun, b, _SUM, n, c); |
| | 44 | $assert($forall (int i: 0..n-1) c[i]==2*a[i]); |
| | 45 | } |
| | 46 | }}} |