forked from scummvm/scummvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitializer_list.h
49 lines (37 loc) · 1.32 KB
/
initializer_list.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef COMMON_INITIALIZER_LIST_H
#define COMMON_INITIALIZER_LIST_H
// Some compiler only have partial support for C++11 and we provide replacements for reatures not available.
#ifdef USE_CXX11
#ifdef NO_CXX11_INITIALIZER_LIST
namespace std {
template<class T> class initializer_list {
public:
typedef T value_type;
typedef const T& reference;
typedef const T& const_reference;
typedef size_t size_type;
typedef const T* iterator;
typedef const T* const_iterator;
constexpr initializer_list() noexcept = default;
constexpr size_t size() const noexcept { return m_size; };
constexpr const T* begin() const noexcept { return m_begin; };
constexpr const T* end() const noexcept { return m_begin + m_size; }
private:
// Note: begin has to be first or the compiler gets very upset
const T* m_begin = { nullptr };
size_t m_size = { 0 };
// The compiler is allowed to call this constructor
constexpr initializer_list(const T* t, size_t s) noexcept : m_begin(t) , m_size(s) {}
};
template<class T> constexpr const T* begin(initializer_list<T> il) noexcept {
return il.begin();
}
template<class T> constexpr const T* end(initializer_list<T> il) noexcept {
return il.end();
}
}
#else
#include <initializer_list>
#endif // NO_CXX11_INITIALIZER_LIST
#endif // USE_CXX11
#endif // COMMON_INITIALIZER_LIST_H