source: cpp/common/nonstd_stl.h @ 364

Last change on this file since 364 was 286, checked in by Maciej Komosinski, 9 years ago

Updated headers

  • Property svn:eol-style set to native
File size: 1.7 KB
Line 
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.
4
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>
11using std::string;
12#ifndef SHP //bada nie ma wstring
13using std::wstring;
14#endif
15
16#include <vector>
17using std::vector;
18
19#include <algorithm> //std::min,max,swap
20using std::min;
21using std::max;
22using 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...
37template <typename T, std::size_t N>
38char (&array_temp(T (&a)[N]))[N];
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.
43template <typename T, std::size_t N>
44char (&array_temp(const T (&a)[N]))[N];
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
47#define ARRAY_LENGTH(x) sizeof(array_temp(x))
48
49
50#endif
Note: See TracBrowser for help on using the repository browser.