File: wrappers_h.txt

package info (click to toggle)
gcc-h8300-hms 1%3A3.4.6%2Bdfsg2-4
  • links: PTS
  • area: main
  • in suites: buster, stretch
  • size: 94,508 kB
  • ctags: 79,901
  • sloc: ansic: 627,399; cpp: 89,017; makefile: 24,796; asm: 21,058; sh: 16,616; yacc: 3,740; perl: 718; xml: 692; lex: 587; exp: 298; awk: 223; pascal: 86; lisp: 59; sed: 37
file content (48 lines) | stat: -rw-r--r-- 1,507 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

/*****************************************************************
 * Functions to help treat arrays in a uniform manner.  These were
 * inspired by a thread on comp.lang.c++.moderated, started by Dietmar
 * Kuehl and contributed to by the rest of the entire planet.
 *
 * beginof (x), endof (x), lengthof (x) now accompany sizeof, where x
 * can be either a container (currently only sequences) or a builtin
 * array (/not/ a pointer).  The beginof/endof are intended for use in
 * the algorithms library, and lengthof is a "sizing" function.
 *
 * Note example:
 *       char  an_array [17];
 *       cerr << lengthof(an_array) << endl;
 * produces assembly code of
 *       mov 17,register0
 *       call ofstream_put
 * i.e., the template function inlining really does work; g++
 * requires -O3 (or -finline-functions) before it does this, though.
 *
 * pedwards 13Nov98
*/
// beginof
template <class T>
  inline typename vector<T>::iterator beginof (vector<T> &v)
  { return v.begin(); }

template <class T, unsigned int sz>
  inline T* beginof (T (&array)[sz]) { return array; }


// endof
template <class T>
  inline typename vector<T>::iterator endof (vector<T> &v)
  { return v.end(); }

template <class T, unsigned int sz>
  inline T* endof (T (&array)[sz]) { return array + sz; }


// lengthof
template <class T>
  inline typename vector<T>::size_type lengthof (vector<T> &v)
  { return v.size(); }

template <class T, unsigned int sz>
  inline unsigned int lengthof (T (&)[sz]) { return sz; }