// This file is a part of Framsticks SDK. http://www.framsticks.com/ // Copyright (C) 1999-2021 Maciej Komosinski and Szymon Ulatowski. // See LICENSE.txt for details. #ifndef _NONSTD_STL_H_ #define _NONSTD_STL_H_ //making STL more standard #include using std::string; #ifndef SHP //STL in the bada OS has no wstring using std::wstring; #endif #include using std::vector; //below: not used since 2020 (these macros are replaced by std::ssize()), may be removed... // ------------------- ARRAY_LENGTH ------------------- //old-fashioned macro, unprotected against the use of the pointer as "x" //#define ARRAY_LENGTH(x) (sizeof(x)/sizeof((x)[0])) //hacker macro that detects some of the misuse cases //#define ARRAY_LENGTH(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x]))))) //template function by intermediate-level devs, as a function it unfortunately does not give a constant at compile time //template inline std::size_t ARRAY_LENGTH( T(&)[N] ) { return N; } //"constexpr" dopiero w C++0x //hacker templates: array of bytes of length N - as long as the array we are asking for... //template //char (&array_temp(T (&a)[N]))[N]; // As litb noted in comments, you need this overload to handle array rvalues // correctly (e.g. when array is a member of a struct returned from function), // since they won't bind to non-const reference in the overload above. //template //char (&array_temp(const T (&a)[N]))[N]; //...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 //#define ARRAY_LENGTH(x) sizeof(array_temp(x)) //final and no longer needed version ;-) (c++17) //#define ARRAY_LENGTH(x) int(std::size(x)) //(still room for improvement because unsigned=risky, ssize() upcoming since C++20) #endif