xref: /openbsd-src/gnu/gcc/libstdc++-v3/docs/html/23_containers/wrappers_h.txt (revision 404b540a9034ac75a6199ad1a32d1bbc7a0d4210)
1
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.
6 *
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.
11 *
12 * Note example:
13 *       char  an_array [17];
14 *       cerr << lengthof(an_array) << endl;
15 * produces assembly code of
16 *       mov 17,register0
17 *       call ofstream_put
18 * i.e., the template function inlining really does work; g++
19 * requires -O3 (or -finline-functions) before it does this, though.
20 *
21 * pedwards 13Nov98
22*/
23// beginof
24template <class T>
25  inline typename vector<T>::iterator beginof (vector<T> &v)
26  { return v.begin(); }
27
28template <class T, unsigned int sz>
29  inline T* beginof (T (&array)[sz]) { return array; }
30
31
32// endof
33template <class T>
34  inline typename vector<T>::iterator endof (vector<T> &v)
35  { return v.end(); }
36
37template <class T, unsigned int sz>
38  inline T* endof (T (&array)[sz]) { return array + sz; }
39
40
41// lengthof
42template <class T>
43  inline typename vector<T>::size_type lengthof (vector<T> &v)
44  { return v.size(); }
45
46template <class T, unsigned int sz>
47  inline unsigned int lengthof (T (&)[sz]) { return sz; }
48
49