blob: f1bea94fa673d51d2224dd4463fc86584d82878b [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 Hinnanted569212011-05-26 18:23:59 +000032 initializer_list() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000033
Howard Hinnanted569212011-05-26 18:23:59 +000034 size_t size() const noexcept;
35 const E* begin() const noexcept;
36 const E* end() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000037};
38
Howard Hinnanted569212011-05-26 18:23:59 +000039template<class E> const E* begin(initializer_list<E> il) noexcept;
40template<class E> const E* end(initializer_list<E> il) noexcept;
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
49#pragma GCC system_header
50
51namespace std // purposefully not versioned
52{
53
54template<class _E>
Howard Hinnant68a8e902010-09-22 15:29:08 +000055class _LIBCPP_VISIBLE initializer_list
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000056{
57 const _E* __begin_;
58 size_t __size_;
59
60 _LIBCPP_ALWAYS_INLINE
Howard Hinnanted569212011-05-26 18:23:59 +000061 initializer_list(const _E* __b, size_t __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000062 : __begin_(__b),
63 __size_(__s)
64 {}
65public:
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 Hinnanted569212011-05-26 18:23:59 +000074 _LIBCPP_ALWAYS_INLINE initializer_list() _NOEXCEPT : __begin_(nullptr), __size_(0) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000075
Howard Hinnanted569212011-05-26 18:23:59 +000076 _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 Hinnantbc8d3f92010-05-11 19:42:16 +000079};
80
Howard Hinnantfcc59382010-05-28 17:53:59 +000081template<class _E>
82inline _LIBCPP_INLINE_VISIBILITY
83const _E*
Howard Hinnanted569212011-05-26 18:23:59 +000084begin(initializer_list<_E> __il) _NOEXCEPT
Howard Hinnantfcc59382010-05-28 17:53:59 +000085{
86 return __il.begin();
87}
88
89template<class _E>
90inline _LIBCPP_INLINE_VISIBILITY
91const _E*
Howard Hinnanted569212011-05-26 18:23:59 +000092end(initializer_list<_E> __il) _NOEXCEPT
Howard Hinnantfcc59382010-05-28 17:53:59 +000093{
94 return __il.end();
95}
96
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000097} // std
98
99#endif // _LIBCPP_INITIALIZER_LIST