src/ring.h

changeset 115
ed884a2fb009
parent 26
3a9e761e4faa
equal deleted inserted replaced
114:4e03b0e2a29f 115:ed884a2fb009
32 template<typename T, typename Tint> 32 template<typename T, typename Tint>
33 _imp::RingAdapter<T, Tint> ring(T&& collection, Tint count); 33 _imp::RingAdapter<T, Tint> ring(T&& collection, Tint count);
34 } 34 }
35 35
36 /* 36 /*
37 * Implements a ring adapter over T. This class corrects indices given to the element-operator so that they're within bounds. 37 * Implements a ring adapter over T. This class corrects indices given to the element-operator so that they're within
38 * The maximum amount can be specified manually. 38 * bounds. The maximum amount can be specified manually.
39 * 39 *
40 * Example: 40 * Example:
41 * 41 *
42 * int A[] = {10,20,30,40}; 42 * int A[] = {10,20,30,40};
43 * ring(A)[0] == A[0 % 4] == A[0] 43 * ring(A)[0] == A[0 % 4] == A[0]
81 return this->count; 81 return this->count;
82 } 82 }
83 }; 83 };
84 84
85 /* 85 /*
86 * Convenience function for RingAdapter so that the template parameter does not have to be provided. The ring amount is assumed 86 * Convenience function for RingAdapter so that the template parameter does not have to be provided. The ring
87 * to be the amount of elements in the collection. 87 * amount is assumed to be the amount of elements in the collection.
88 */ 88 */
89 template<typename T> 89 template<typename T>
90 iter::_imp::RingAdapter<T, int> iter::ring(T&& collection) 90 iter::_imp::RingAdapter<T, int> iter::ring(T&& collection)
91 { 91 {
92 return {collection, countof(collection)}; 92 return {collection, countof(collection)};

mercurial