Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===----------------------- initializer_list -----------------------------===// |
| 3 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_INITIALIZER_LIST |
| 11 | #define _LIBCPP_INITIALIZER_LIST |
| 12 | |
| 13 | /* |
| 14 | initializer_list synopsis |
| 15 | |
| 16 | namespace std |
| 17 | { |
| 18 | |
| 19 | template<class E> |
| 20 | class initializer_list |
| 21 | { |
| 22 | public: |
| 23 | typedef E value_type; |
| 24 | typedef const E& reference; |
| 25 | typedef const E& const_reference; |
| 26 | typedef size_t size_type; |
| 27 | |
| 28 | typedef const E* iterator; |
| 29 | typedef const E* const_iterator; |
| 30 | |
Howard Hinnant | 9328811 | 2013-08-26 20:11:32 +0000 | [diff] [blame] | 31 | initializer_list() noexcept; // constexpr in C++14 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 32 | |
Howard Hinnant | 9328811 | 2013-08-26 20:11:32 +0000 | [diff] [blame] | 33 | size_t size() const noexcept; // constexpr in C++14 |
| 34 | const E* begin() const noexcept; // constexpr in C++14 |
| 35 | const E* end() const noexcept; // constexpr in C++14 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 36 | }; |
| 37 | |
Howard Hinnant | 9328811 | 2013-08-26 20:11:32 +0000 | [diff] [blame] | 38 | template<class E> const E* begin(initializer_list<E> il) noexcept; // constexpr in C++14 |
| 39 | template<class E> const E* end(initializer_list<E> il) noexcept; // constexpr in C++14 |
Howard Hinnant | 9d4a286 | 2010-05-28 17:53:59 +0000 | [diff] [blame] | 40 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 41 | } // std |
| 42 | |
| 43 | */ |
| 44 | |
| 45 | #include <__config> |
| 46 | #include <cstddef> |
| 47 | |
Howard Hinnant | 073458b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 48 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 49 | #pragma GCC system_header |
Howard Hinnant | 073458b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 50 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 51 | |
| 52 | namespace std // purposefully not versioned |
| 53 | { |
| 54 | |
Eric Fiselier | 94b2bde | 2017-04-18 23:09:36 +0000 | [diff] [blame] | 55 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 56 | |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 57 | template<class _Ep> |
Eric Fiselier | e2f2d1e | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 58 | class _LIBCPP_TEMPLATE_VIS initializer_list |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 59 | { |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 60 | const _Ep* __begin_; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 61 | size_t __size_; |
| 62 | |
Louis Dionne | dc7200b | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 63 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9328811 | 2013-08-26 20:11:32 +0000 | [diff] [blame] | 64 | _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 65 | initializer_list(const _Ep* __b, size_t __s) _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 66 | : __begin_(__b), |
| 67 | __size_(__s) |
| 68 | {} |
| 69 | public: |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 70 | typedef _Ep value_type; |
| 71 | typedef const _Ep& reference; |
| 72 | typedef const _Ep& const_reference; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 73 | typedef size_t size_type; |
| 74 | |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 75 | typedef const _Ep* iterator; |
| 76 | typedef const _Ep* const_iterator; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 77 | |
Louis Dionne | dc7200b | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 78 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9328811 | 2013-08-26 20:11:32 +0000 | [diff] [blame] | 79 | _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 80 | initializer_list() _NOEXCEPT : __begin_(nullptr), __size_(0) {} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 81 | |
Louis Dionne | dc7200b | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 82 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9328811 | 2013-08-26 20:11:32 +0000 | [diff] [blame] | 83 | _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 84 | size_t size() const _NOEXCEPT {return __size_;} |
Louis Dionne | a2a1ec2 | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 85 | |
Louis Dionne | dc7200b | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 86 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9328811 | 2013-08-26 20:11:32 +0000 | [diff] [blame] | 87 | _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 88 | const _Ep* begin() const _NOEXCEPT {return __begin_;} |
| 89 | |
Louis Dionne | dc7200b | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 90 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9328811 | 2013-08-26 20:11:32 +0000 | [diff] [blame] | 91 | _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 92 | const _Ep* end() const _NOEXCEPT {return __begin_ + __size_;} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 93 | }; |
| 94 | |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 95 | template<class _Ep> |
Howard Hinnant | 9d4a286 | 2010-05-28 17:53:59 +0000 | [diff] [blame] | 96 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9328811 | 2013-08-26 20:11:32 +0000 | [diff] [blame] | 97 | _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 98 | const _Ep* |
| 99 | begin(initializer_list<_Ep> __il) _NOEXCEPT |
Howard Hinnant | 9d4a286 | 2010-05-28 17:53:59 +0000 | [diff] [blame] | 100 | { |
| 101 | return __il.begin(); |
| 102 | } |
| 103 | |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 104 | template<class _Ep> |
Howard Hinnant | 9d4a286 | 2010-05-28 17:53:59 +0000 | [diff] [blame] | 105 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9328811 | 2013-08-26 20:11:32 +0000 | [diff] [blame] | 106 | _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 107 | const _Ep* |
| 108 | end(initializer_list<_Ep> __il) _NOEXCEPT |
Howard Hinnant | 9d4a286 | 2010-05-28 17:53:59 +0000 | [diff] [blame] | 109 | { |
| 110 | return __il.end(); |
| 111 | } |
| 112 | |
Eric Fiselier | 94b2bde | 2017-04-18 23:09:36 +0000 | [diff] [blame] | 113 | #endif // !defined(_LIBCPP_CXX03_LANG) |
Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 114 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 115 | } // std |
| 116 | |
| 117 | #endif // _LIBCPP_INITIALIZER_LIST |