COMMON: Move std::initializer_list to scummsys.h

This commit is contained in:
Thierry Crozat 2022-08-31 22:14:16 +01:00
parent e5877985ff
commit e36abe967e
5 changed files with 44 additions and 48 deletions

View File

@ -26,7 +26,6 @@
#include "common/algorithm.h"
#include "common/textconsole.h" // For error()
#include "common/memory.h"
#include "common/initializer_list.h"
namespace Common {

View File

@ -1,45 +0,0 @@
#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 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 // COMMON_INITIALIZER_LIST_H

View File

@ -504,6 +504,50 @@ namespace std {
}
#endif
//
// std::initializer_list
// Provide replacement when not available
//
#if defined(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 _size; };
constexpr const T *begin() const noexcept { return _begin; };
constexpr const T *end() const noexcept { return _begin + _size; }
private:
// Note: begin has to be first or the compiler may get very upset
const T *_begin = { nullptr };
size_t _size = { 0 };
// The compiler is allowed to call this constructor
constexpr initializer_list(const T* t, size_t s) noexcept : _begin(t) , _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
#include "common/forbidden.h"
#endif

View File

@ -23,7 +23,6 @@
#define AGS_STD_INITIALIZER_LIST_H
#include "common/scummsys.h"
#include "common/initializer_list.h"
namespace AGS3 {
namespace std {

View File

@ -27,7 +27,6 @@
#include "common/scummsys.h"
#include "common/algorithm.h"
#include "common/memory.h"
#include "common/initializer_list.h"
namespace AGS3 {
namespace std {