Ignore:
Timestamp:
04/16/21 15:55:34 (3 years ago)
Author:
Maciej Komosinski
Message:

Used std::min(), std::max() explicitly to avoid compiler confusion. Used std::size() explicitly instead of the equivalent macro

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/common/nonstd_stl.h

    r1108 r1130  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2021  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    66#define _NONSTD_STL_H_
    77
    8 //stl jak sama nazwa glosi wcale nie jest nonstd
     8//making STL more standard
    99
    1010#include <string>
    1111using std::string;
    12 #ifndef SHP //bada nie ma wstring
     12#ifndef SHP //STL in the bada OS has no wstring
    1313using std::wstring;
    1414#endif
     
    1717using std::vector;
    1818
    19 #include <algorithm> //std::min,max,swap
    20 using std::min;
    21 using std::max;
    22 using std::swap;
    2319
     20//below: not used since 2020 (these macros are replaced by std::ssize()), may be removed...
    2421
    2522// ------------------- ARRAY_LENGTH -------------------
    2623
    27 //staromodne makro, niezabezpieczone przed uzyciem wskaznika w roli "x"
     24//old-fashioned macro, unprotected against the use of the pointer as "x"
    2825//#define ARRAY_LENGTH(x) (sizeof(x)/sizeof((x)[0]))
    2926
    30 //hakerskie makro ktore wykrywa czesc pomy³kowych przypadkow uzycia
     27//hacker macro that detects some of the misuse cases
    3128//#define ARRAY_LENGTH(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
    3229
    33 //szablonowa funkcja pisana przez sredniozaawansowanych, jak to funkcja - nie daje niestety sta³ej w czasie kompilacji
     30//template function by intermediate-level devs, as a function it unfortunately does not give a constant at compile time
    3431//template<typename T, std::size_t N> inline std::size_t ARRAY_LENGTH( T(&)[N] ) { return N; } //"constexpr" dopiero w C++0x
    3532
    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...
    3734//template <typename T, std::size_t N>
    3835//char (&array_temp(T (&a)[N]))[N];
     
    4441//char (&array_temp(const T (&a)[N]))[N];
    4542
    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
     43//...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
    4744//#define ARRAY_LENGTH(x) sizeof(array_temp(x))
    4845
    4946//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)
    5149
    5250
Note: See TracChangeset for help on using the changeset viewer.