1// Copyright 2017 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5//
6// Provides std::initializer_list<T> on behalf of the Magenta toolchain
7// when compiling without the C++ standard library.
8//
9
10#pragma once
11
12// This implementation is known to be compatible with our GCC and Clang toolchains.
13#if defined(__GNUC__) || defined(__clang__)
14
15#include <stddef.h>
16
17namespace std {
18template <typename T>
19class initializer_list {
20public:
21    using value_type = T;
22    using reference = const T&;
23    using const_reference = const T&;
24    using size_type = size_t;
25    using iterator = const T*;
26    using const_iterator = const T*;
27
28    constexpr initializer_list()
29        : items_(nullptr), size_(0u) {}
30
31    constexpr size_t size() const { return size_; }
32    constexpr const T* begin() const { return items_; }
33    constexpr const T* end() const { return items_ + size_; }
34
35private:
36    constexpr initializer_list(const T* items, size_t size)
37        : items_(items), size_(size) {}
38
39    const T* items_;
40    size_t size_;
41};
42} // namespace std
43
44#else
45#error "std::initializer_list<T> not supported by this toolchain"
46#endif // defined(__GNUC__) || defined(__clang__)
47
48// vim: syntax=cpp
49