blob: 893736f57ead6da01d7f82bb10df845411dd398c [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001// -*- C++ -*-
2//===----------------------- initializer_list -----------------------------===//
3//
Chandler Carruth57b08b02019-01-19 10:56:40 +00004// 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 Hinnant3e519522010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_INITIALIZER_LIST
11#define _LIBCPP_INITIALIZER_LIST
12
13/*
14 initializer_list synopsis
15
16namespace std
17{
18
19template<class E>
20class initializer_list
21{
22public:
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 Hinnant93288112013-08-26 20:11:32 +000031 initializer_list() noexcept; // constexpr in C++14
Howard Hinnant3e519522010-05-11 19:42:16 +000032
Howard Hinnant93288112013-08-26 20:11:32 +000033 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 Hinnant3e519522010-05-11 19:42:16 +000036};
37
Howard Hinnant93288112013-08-26 20:11:32 +000038template<class E> const E* begin(initializer_list<E> il) noexcept; // constexpr in C++14
39template<class E> const E* end(initializer_list<E> il) noexcept; // constexpr in C++14
Howard Hinnant9d4a2862010-05-28 17:53:59 +000040
Howard Hinnant3e519522010-05-11 19:42:16 +000041} // std
42
43*/
44
45#include <__config>
46#include <cstddef>
47
Howard Hinnant073458b2011-10-17 20:05:10 +000048#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnant3e519522010-05-11 19:42:16 +000049#pragma GCC system_header
Howard Hinnant073458b2011-10-17 20:05:10 +000050#endif
Howard Hinnant3e519522010-05-11 19:42:16 +000051
52namespace std // purposefully not versioned
53{
54
Eric Fiselier94b2bde2017-04-18 23:09:36 +000055#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant54976f22011-08-12 21:56:02 +000056
Howard Hinnantc003db12011-11-29 18:15:50 +000057template<class _Ep>
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +000058class _LIBCPP_TEMPLATE_VIS initializer_list
Howard Hinnant3e519522010-05-11 19:42:16 +000059{
Howard Hinnantc003db12011-11-29 18:15:50 +000060 const _Ep* __begin_;
Howard Hinnant3e519522010-05-11 19:42:16 +000061 size_t __size_;
62
Louis Dionnedc7200b2018-07-11 23:14:33 +000063 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant93288112013-08-26 20:11:32 +000064 _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc003db12011-11-29 18:15:50 +000065 initializer_list(const _Ep* __b, size_t __s) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +000066 : __begin_(__b),
67 __size_(__s)
68 {}
69public:
Howard Hinnantc003db12011-11-29 18:15:50 +000070 typedef _Ep value_type;
71 typedef const _Ep& reference;
72 typedef const _Ep& const_reference;
Howard Hinnant3e519522010-05-11 19:42:16 +000073 typedef size_t size_type;
74
Howard Hinnantc003db12011-11-29 18:15:50 +000075 typedef const _Ep* iterator;
76 typedef const _Ep* const_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +000077
Louis Dionnedc7200b2018-07-11 23:14:33 +000078 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant93288112013-08-26 20:11:32 +000079 _LIBCPP_CONSTEXPR_AFTER_CXX11
80 initializer_list() _NOEXCEPT : __begin_(nullptr), __size_(0) {}
Howard Hinnant3e519522010-05-11 19:42:16 +000081
Louis Dionnedc7200b2018-07-11 23:14:33 +000082 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant93288112013-08-26 20:11:32 +000083 _LIBCPP_CONSTEXPR_AFTER_CXX11
84 size_t size() const _NOEXCEPT {return __size_;}
Louis Dionnea2a1ec22019-05-29 16:01:36 +000085
Louis Dionnedc7200b2018-07-11 23:14:33 +000086 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant93288112013-08-26 20:11:32 +000087 _LIBCPP_CONSTEXPR_AFTER_CXX11
88 const _Ep* begin() const _NOEXCEPT {return __begin_;}
89
Louis Dionnedc7200b2018-07-11 23:14:33 +000090 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant93288112013-08-26 20:11:32 +000091 _LIBCPP_CONSTEXPR_AFTER_CXX11
92 const _Ep* end() const _NOEXCEPT {return __begin_ + __size_;}
Howard Hinnant3e519522010-05-11 19:42:16 +000093};
94
Howard Hinnantc003db12011-11-29 18:15:50 +000095template<class _Ep>
Howard Hinnant9d4a2862010-05-28 17:53:59 +000096inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant93288112013-08-26 20:11:32 +000097_LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc003db12011-11-29 18:15:50 +000098const _Ep*
99begin(initializer_list<_Ep> __il) _NOEXCEPT
Howard Hinnant9d4a2862010-05-28 17:53:59 +0000100{
101 return __il.begin();
102}
103
Howard Hinnantc003db12011-11-29 18:15:50 +0000104template<class _Ep>
Howard Hinnant9d4a2862010-05-28 17:53:59 +0000105inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant93288112013-08-26 20:11:32 +0000106_LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnantc003db12011-11-29 18:15:50 +0000107const _Ep*
108end(initializer_list<_Ep> __il) _NOEXCEPT
Howard Hinnant9d4a2862010-05-28 17:53:59 +0000109{
110 return __il.end();
111}
112
Eric Fiselier94b2bde2017-04-18 23:09:36 +0000113#endif // !defined(_LIBCPP_CXX03_LANG)
Howard Hinnant54976f22011-08-12 21:56:02 +0000114
Howard Hinnant3e519522010-05-11 19:42:16 +0000115} // std
116
117#endif // _LIBCPP_INITIALIZER_LIST