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