2 /*****************************************************************
3 * Functions to help treat arrays in a uniform manner. These were
4 * inspired by a thread on comp.lang.c++.moderated, started by Dietmar
5 * Kuehl and contributed to by the rest of the entire planet.
7 * beginof (x), endof (x), lengthof (x) now accompany sizeof, where x
8 * can be either a container (currently only sequences) or a builtin
9 * array (/not/ a pointer). The beginof/endof are intended for use in
10 * the algorithms library, and lengthof is a "sizing" function.
14 * cerr << lengthof(an_array) << endl;
15 * produces assembly code of
18 * i.e., the template function inlining really does work; g++
19 * requires -O3 (or -finline-functions) before it does this, though.
25 inline typename vector<T>::iterator beginof (vector<T> &v)
28 template <class T, unsigned int sz>
29 inline T* beginof (T (&array)[sz]) { return array; }
34 inline typename vector<T>::iterator endof (vector<T> &v)
37 template <class T, unsigned int sz>
38 inline T* endof (T (&array)[sz]) { return array + sz; }
43 inline typename vector<T>::size_type lengthof (vector<T> &v)
46 template <class T, unsigned int sz>
47 inline unsigned int lengthof (T (&)[sz]) { return sz; }