Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===----------------------- initializer_list -----------------------------===// |
| 3 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP_INITIALIZER_LIST |
| 12 | #define _LIBCPP_INITIALIZER_LIST |
| 13 | |
| 14 | /* |
| 15 | initializer_list synopsis |
| 16 | |
| 17 | namespace std |
| 18 | { |
| 19 | |
| 20 | template<class E> |
| 21 | class initializer_list |
| 22 | { |
| 23 | public: |
| 24 | typedef E value_type; |
| 25 | typedef const E& reference; |
| 26 | typedef const E& const_reference; |
| 27 | typedef size_t size_type; |
| 28 | |
| 29 | typedef const E* iterator; |
| 30 | typedef const E* const_iterator; |
| 31 | |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame^] | 32 | initializer_list() noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 33 | |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame^] | 34 | size_t size() const noexcept; |
| 35 | const E* begin() const noexcept; |
| 36 | const E* end() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 37 | }; |
| 38 | |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame^] | 39 | template<class E> const E* begin(initializer_list<E> il) noexcept; |
| 40 | template<class E> const E* end(initializer_list<E> il) noexcept; |
Howard Hinnant | fcc5938 | 2010-05-28 17:53:59 +0000 | [diff] [blame] | 41 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 42 | } // std |
| 43 | |
| 44 | */ |
| 45 | |
| 46 | #include <__config> |
| 47 | #include <cstddef> |
| 48 | |
| 49 | #pragma GCC system_header |
| 50 | |
| 51 | namespace std // purposefully not versioned |
| 52 | { |
| 53 | |
| 54 | template<class _E> |
Howard Hinnant | 68a8e90 | 2010-09-22 15:29:08 +0000 | [diff] [blame] | 55 | class _LIBCPP_VISIBLE initializer_list |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 56 | { |
| 57 | const _E* __begin_; |
| 58 | size_t __size_; |
| 59 | |
| 60 | _LIBCPP_ALWAYS_INLINE |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame^] | 61 | initializer_list(const _E* __b, size_t __s) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 62 | : __begin_(__b), |
| 63 | __size_(__s) |
| 64 | {} |
| 65 | public: |
| 66 | typedef _E value_type; |
| 67 | typedef const _E& reference; |
| 68 | typedef const _E& const_reference; |
| 69 | typedef size_t size_type; |
| 70 | |
| 71 | typedef const _E* iterator; |
| 72 | typedef const _E* const_iterator; |
| 73 | |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame^] | 74 | _LIBCPP_ALWAYS_INLINE initializer_list() _NOEXCEPT : __begin_(nullptr), __size_(0) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 75 | |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame^] | 76 | _LIBCPP_ALWAYS_INLINE size_t size() const _NOEXCEPT {return __size_;} |
| 77 | _LIBCPP_ALWAYS_INLINE const _E* begin() const _NOEXCEPT {return __begin_;} |
| 78 | _LIBCPP_ALWAYS_INLINE const _E* end() const _NOEXCEPT {return __begin_ + __size_;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 79 | }; |
| 80 | |
Howard Hinnant | fcc5938 | 2010-05-28 17:53:59 +0000 | [diff] [blame] | 81 | template<class _E> |
| 82 | inline _LIBCPP_INLINE_VISIBILITY |
| 83 | const _E* |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame^] | 84 | begin(initializer_list<_E> __il) _NOEXCEPT |
Howard Hinnant | fcc5938 | 2010-05-28 17:53:59 +0000 | [diff] [blame] | 85 | { |
| 86 | return __il.begin(); |
| 87 | } |
| 88 | |
| 89 | template<class _E> |
| 90 | inline _LIBCPP_INLINE_VISIBILITY |
| 91 | const _E* |
Howard Hinnant | ed56921 | 2011-05-26 18:23:59 +0000 | [diff] [blame^] | 92 | end(initializer_list<_E> __il) _NOEXCEPT |
Howard Hinnant | fcc5938 | 2010-05-28 17:53:59 +0000 | [diff] [blame] | 93 | { |
| 94 | return __il.end(); |
| 95 | } |
| 96 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 97 | } // std |
| 98 | |
| 99 | #endif // _LIBCPP_INITIALIZER_LIST |