blob: 663e49b6ee43e38d768bdeb92836e027d913268f [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===----------------------- initializer_list -----------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_INITIALIZER_LIST
12#define _LIBCPP_INITIALIZER_LIST
13
14/*
15 initializer_list synopsis
16
17namespace std
18{
19
20template<class E>
21class initializer_list
22{
23public:
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 Hinnante1c5f9e2013-08-26 20:11:32 +000032 initializer_list() noexcept; // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000033
Howard Hinnante1c5f9e2013-08-26 20:11:32 +000034 size_t size() const noexcept; // constexpr in C++14
35 const E* begin() const noexcept; // constexpr in C++14
36 const E* end() const noexcept; // constexpr in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000037};
38
Howard Hinnante1c5f9e2013-08-26 20:11:32 +000039template<class E> const E* begin(initializer_list<E> il) noexcept; // constexpr in C++14
40template<class E> const E* end(initializer_list<E> il) noexcept; // constexpr in C++14
Howard Hinnantfcc59382010-05-28 17:53:59 +000041
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000042} // std
43
44*/
45
46#include <__config>
47#include <cstddef>
48
Howard Hinnant08e17472011-10-17 20:05:10 +000049#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000050#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +000051#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000052
53namespace std // purposefully not versioned
54{
55
Howard Hinnante3e32912011-08-12 21:56:02 +000056#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
57
Howard Hinnant99968442011-11-29 18:15:50 +000058template<class _Ep>
Howard Hinnant0f678bd2013-08-12 18:38:34 +000059class _LIBCPP_TYPE_VIS_ONLY initializer_list
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000060{
Howard Hinnant99968442011-11-29 18:15:50 +000061 const _Ep* __begin_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000062 size_t __size_;
63
64 _LIBCPP_ALWAYS_INLINE
Howard Hinnante1c5f9e2013-08-26 20:11:32 +000065 _LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant99968442011-11-29 18:15:50 +000066 initializer_list(const _Ep* __b, size_t __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000067 : __begin_(__b),
68 __size_(__s)
69 {}
70public:
Howard Hinnant99968442011-11-29 18:15:50 +000071 typedef _Ep value_type;
72 typedef const _Ep& reference;
73 typedef const _Ep& const_reference;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000074 typedef size_t size_type;
75
Howard Hinnant99968442011-11-29 18:15:50 +000076 typedef const _Ep* iterator;
77 typedef const _Ep* const_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000078
Howard Hinnante1c5f9e2013-08-26 20:11:32 +000079 _LIBCPP_ALWAYS_INLINE
80 _LIBCPP_CONSTEXPR_AFTER_CXX11
81 initializer_list() _NOEXCEPT : __begin_(nullptr), __size_(0) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000082
Howard Hinnante1c5f9e2013-08-26 20:11:32 +000083 _LIBCPP_ALWAYS_INLINE
84 _LIBCPP_CONSTEXPR_AFTER_CXX11
85 size_t size() const _NOEXCEPT {return __size_;}
86
87 _LIBCPP_ALWAYS_INLINE
88 _LIBCPP_CONSTEXPR_AFTER_CXX11
89 const _Ep* begin() const _NOEXCEPT {return __begin_;}
90
91 _LIBCPP_ALWAYS_INLINE
92 _LIBCPP_CONSTEXPR_AFTER_CXX11
93 const _Ep* end() const _NOEXCEPT {return __begin_ + __size_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000094};
95
Howard Hinnant99968442011-11-29 18:15:50 +000096template<class _Ep>
Howard Hinnantfcc59382010-05-28 17:53:59 +000097inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante1c5f9e2013-08-26 20:11:32 +000098_LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant99968442011-11-29 18:15:50 +000099const _Ep*
100begin(initializer_list<_Ep> __il) _NOEXCEPT
Howard Hinnantfcc59382010-05-28 17:53:59 +0000101{
102 return __il.begin();
103}
104
Howard Hinnant99968442011-11-29 18:15:50 +0000105template<class _Ep>
Howard Hinnantfcc59382010-05-28 17:53:59 +0000106inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante1c5f9e2013-08-26 20:11:32 +0000107_LIBCPP_CONSTEXPR_AFTER_CXX11
Howard Hinnant99968442011-11-29 18:15:50 +0000108const _Ep*
109end(initializer_list<_Ep> __il) _NOEXCEPT
Howard Hinnantfcc59382010-05-28 17:53:59 +0000110{
111 return __il.end();
112}
113
Howard Hinnante3e32912011-08-12 21:56:02 +0000114#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
115
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000116} // std
117
118#endif // _LIBCPP_INITIALIZER_LIST