source: cpp/common/nonstd_stl.h @ 113

Last change on this file since 113 was 109, checked in by sz, 10 years ago

source reorganization (see README)
new feature added: part/joint shapes (see frams/_demos/part_shapes.cpp)

  • Property svn:eol-style set to native
File size: 1.6 KB
Line 
1#ifndef _NONSTD_STL_H_
2#define _NONSTD_STL_H_
3
4//stl jak sama nazwa glosi wcale nie jest nonstd
5
6#include <string>
7using std::string;
8#ifndef SHP //bada nie ma wstring
9using std::wstring;
10#endif
11
12#include <vector>
13using std::vector;
14
15#include <algorithm> //std::min,max,swap
16using std::min;
17using std::max;
18using std::swap;
19
20
21// ------------------- ARRAY_LENGTH -------------------
22
23//staromodne makro, niezabezpieczone przed uzyciem wskaznika w roli "x"
24//#define ARRAY_LENGTH(x) (sizeof(x)/sizeof((x)[0]))
25
26//hakerskie makro ktore wykrywa czesc pomy³kowych przypadkow uzycia
27//#define ARRAY_LENGTH(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
28
29//szablonowa funkcja pisana przez sredniozaawansowanych, jak to funkcja - nie daje niestety sta³ej w czasie kompilacji
30//template<typename T, std::size_t N> inline std::size_t ARRAY_LENGTH( T(&)[N] ) { return N; } //"constexpr" dopiero w C++0x
31
32//szablony hakerskie: tablica bajtow o dlugosci N - tak dluga jak tablica o któr¹ pytamy...
33template <typename T, std::size_t N>
34char (&array_temp(T (&a)[N]))[N];
35
36// As litb noted in comments, you need this overload to handle array rvalues
37// correctly (e.g. when array is a member of a struct returned from function),
38// since they won't bind to non-const reference in the overload above.
39template <typename T, std::size_t N>
40char (&array_temp(const T (&a)[N]))[N];
41
42//...ktor¹ mozna potem uzyc normalnie w sizeof i dzieki temu mamy const w compile-time. tak uzyteczne jak staromodne makro ale z pelna kontrola bledow
43#define ARRAY_LENGTH(x) sizeof(array_temp(x))
44
45
46#endif
Note: See TracBrowser for help on using the repository browser.