-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathinitializer_list.h
104 lines (68 loc) · 3.13 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
///////////////////////////////////////////////////////////////////////////////
// Copyright (c) Electronic Arts Inc. All rights reserved.
//
// This file #includes <initializer_list> if it's available, else it defines
// its own version of std::initializer_list. It does not define eastl::initializer_list
// because that would not provide any use, due to how the C++11 Standard works.
///////////////////////////////////////////////////////////////////////////////
#ifndef EASTL_INITIALIZER_LIST_H
#define EASTL_INITIALIZER_LIST_H
#include <eastl/internal/config.h>
#include <eastl/EABase/eahave.h>
#if defined(EASTL_PRAGMA_ONCE_SUPPORTED)
#pragma once // Some compilers (e.g. VC++) benefit significantly from using this. We've measured 3-4% build speed improvements in apps as a result.
#endif
#if defined(EA_HAVE_CPP11_INITIALIZER_LIST) // If the compiler can generate calls to std::initializer_list...
// The initializer_list type must be declared in the std namespace, as that's the
// namespace the compiler uses when generating code to use it.
EA_DISABLE_ALL_VC_WARNINGS()
#include <initializer_list>
EA_RESTORE_ALL_VC_WARNINGS()
#else
// If you get an error here about initializer_list being already defined, then the EA_HAVE_CPP11_INITIALIZER_LIST define from <eastl/EABase/eahave.h> needs to be updated.
namespace std
{
// See the C++11 Standard, section 18.9.
template<class E>
class initializer_list
{
public:
typedef E value_type;
typedef const E& reference;
typedef const E& const_reference;
typedef size_t size_type;
typedef const E* iterator; // Must be const, as initializer_list (and its mpArray) is an immutable temp object.
typedef const E* const_iterator;
private:
iterator mpArray;
size_type mArraySize;
// This constructor is private, but the C++ compiler has the ability to call it, as per the C++11 Standard.
initializer_list(const_iterator pArray, size_type arraySize)
: mpArray(pArray), mArraySize(arraySize) { }
public:
initializer_list() EASTL_NOEXCEPT // EASTL_NOEXCEPT requires a recent version of EABase.
: mpArray(NULL), mArraySize(0) { }
#if defined(EA_COMPILER_MSVC)
// MSVC generates constructor calls with two pointers instead of one pointer + size. The constructor is
// public.
// See: https://docs.microsoft.com/en-us/cpp/standard-library/initializer-list-class#initializer_list
initializer_list(const_iterator pFirst, const_iterator pLast) EASTL_NOEXCEPT
: mpArray(pFirst), mArraySize(pLast - pFirst) { }
#endif
size_type size() const EASTL_NOEXCEPT { return mArraySize; }
const_iterator begin() const EASTL_NOEXCEPT { return mpArray; } // Must be const_iterator, as initializer_list (and its mpArray) is an immutable temp object.
const_iterator end() const EASTL_NOEXCEPT { return mpArray + mArraySize; }
};
template<class T>
const T* begin(std::initializer_list<T> ilist) EASTL_NOEXCEPT
{
return ilist.begin();
}
template<class T>
const T* end(std::initializer_list<T> ilist) EASTL_NOEXCEPT
{
return ilist.end();
}
}
#endif
#endif // Header include guard