[286] | 1 | // This file is a part of Framsticks SDK. http://www.framsticks.com/ |
---|
| 2 | // Copyright (C) 1999-2015 Maciej Komosinski and Szymon Ulatowski. |
---|
| 3 | // See LICENSE.txt for details. |
---|
[122] | 4 | |
---|
[109] | 5 | #ifndef _NONSTD_STL_H_ |
---|
| 6 | #define _NONSTD_STL_H_ |
---|
| 7 | |
---|
| 8 | //stl jak sama nazwa glosi wcale nie jest nonstd |
---|
| 9 | |
---|
| 10 | #include <string> |
---|
| 11 | using std::string; |
---|
| 12 | #ifndef SHP //bada nie ma wstring |
---|
| 13 | using std::wstring; |
---|
| 14 | #endif |
---|
| 15 | |
---|
| 16 | #include <vector> |
---|
| 17 | using std::vector; |
---|
| 18 | |
---|
| 19 | #include <algorithm> //std::min,max,swap |
---|
| 20 | using std::min; |
---|
| 21 | using std::max; |
---|
| 22 | using std::swap; |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | // ------------------- ARRAY_LENGTH ------------------- |
---|
| 26 | |
---|
| 27 | //staromodne makro, niezabezpieczone przed uzyciem wskaznika w roli "x" |
---|
| 28 | //#define ARRAY_LENGTH(x) (sizeof(x)/sizeof((x)[0])) |
---|
| 29 | |
---|
| 30 | //hakerskie makro ktore wykrywa czesc pomy³kowych przypadkow uzycia |
---|
| 31 | //#define ARRAY_LENGTH(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x]))))) |
---|
| 32 | |
---|
| 33 | //szablonowa funkcja pisana przez sredniozaawansowanych, jak to funkcja - nie daje niestety sta³ej w czasie kompilacji |
---|
| 34 | //template<typename T, std::size_t N> inline std::size_t ARRAY_LENGTH( T(&)[N] ) { return N; } //"constexpr" dopiero w C++0x |
---|
| 35 | |
---|
| 36 | //szablony hakerskie: tablica bajtow o dlugosci N - tak dluga jak tablica o któr¹ pytamy... |
---|
[1027] | 37 | //template <typename T, std::size_t N> |
---|
| 38 | //char (&array_temp(T (&a)[N]))[N]; |
---|
[109] | 39 | |
---|
| 40 | // As litb noted in comments, you need this overload to handle array rvalues |
---|
| 41 | // correctly (e.g. when array is a member of a struct returned from function), |
---|
| 42 | // since they won't bind to non-const reference in the overload above. |
---|
[1027] | 43 | //template <typename T, std::size_t N> |
---|
| 44 | //char (&array_temp(const T (&a)[N]))[N]; |
---|
[109] | 45 | |
---|
| 46 | //...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 |
---|
[1027] | 47 | //#define ARRAY_LENGTH(x) sizeof(array_temp(x)) |
---|
[109] | 48 | |
---|
[1027] | 49 | //final and no longer needed version ;-) (c++17) |
---|
| 50 | #define ARRAY_LENGTH(x) std::size(x) |
---|
[109] | 51 | |
---|
[1027] | 52 | |
---|
[109] | 53 | #endif |
---|