Changeset 1130 for cpp/common/nonstd_stl.h
- Timestamp:
- 04/16/21 15:55:34 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/common/nonstd_stl.h
r1108 r1130 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 15Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2021 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 6 6 #define _NONSTD_STL_H_ 7 7 8 // stl jak sama nazwa glosi wcale nie jest nonstd8 //making STL more standard 9 9 10 10 #include <string> 11 11 using std::string; 12 #ifndef SHP // bada nie mawstring12 #ifndef SHP //STL in the bada OS has no wstring 13 13 using std::wstring; 14 14 #endif … … 17 17 using std::vector; 18 18 19 #include <algorithm> //std::min,max,swap20 using std::min;21 using std::max;22 using std::swap;23 19 20 //below: not used since 2020 (these macros are replaced by std::ssize()), may be removed... 24 21 25 22 // ------------------- ARRAY_LENGTH ------------------- 26 23 27 // staromodne makro, niezabezpieczone przed uzyciem wskaznika w roli"x"24 //old-fashioned macro, unprotected against the use of the pointer as "x" 28 25 //#define ARRAY_LENGTH(x) (sizeof(x)/sizeof((x)[0])) 29 26 30 //ha kerskie makro ktore wykrywa czesc pomy³kowych przypadkow uzycia27 //hacker macro that detects some of the misuse cases 31 28 //#define ARRAY_LENGTH(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x]))))) 32 29 33 // szablonowa funkcja pisana przez sredniozaawansowanych, jak to funkcja - nie daje niestety sta³ej w czasie kompilacji30 //template function by intermediate-level devs, as a function it unfortunately does not give a constant at compile time 34 31 //template<typename T, std::size_t N> inline std::size_t ARRAY_LENGTH( T(&)[N] ) { return N; } //"constexpr" dopiero w C++0x 35 32 36 // szablony hakerskie: tablica bajtow o dlugosci N - tak dluga jak tablica o któr¹ pytamy...33 //hacker templates: array of bytes of length N - as long as the array we are asking for... 37 34 //template <typename T, std::size_t N> 38 35 //char (&array_temp(T (&a)[N]))[N]; … … 44 41 //char (&array_temp(const T (&a)[N]))[N]; 45 42 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 bledow43 //...which can then be used in sizeof and thus we have const in compile-time. This is as useful as the old-fashioned macro above, but with full error control 47 44 //#define ARRAY_LENGTH(x) sizeof(array_temp(x)) 48 45 49 46 //final and no longer needed version ;-) (c++17) 50 #define ARRAY_LENGTH(x) int(std::size(x)) 47 //#define ARRAY_LENGTH(x) int(std::size(x)) 48 //(still room for improvement because unsigned=risky, ssize() upcoming since C++20) 51 49 52 50
Note: See TracChangeset
for help on using the changeset viewer.