blob: 745d3bd787f8953ece839863e9339d8c2617d821 [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
Howard Hinnante3e32912011-08-12 21:56:02 +000054#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
55
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000056template<class _E>
Howard Hinnant68a8e902010-09-22 15:29:08 +000057class _LIBCPP_VISIBLE initializer_list
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000058{
59 const _E* __begin_;
60 size_t __size_;
61
62 _LIBCPP_ALWAYS_INLINE
Howard Hinnanted569212011-05-26 18:23:59 +000063 initializer_list(const _E* __b, size_t __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000064 : __begin_(__b),
65 __size_(__s)
66 {}
67public:
68 typedef _E value_type;
69 typedef const _E& reference;
70 typedef const _E& const_reference;
71 typedef size_t size_type;
72
73 typedef const _E* iterator;
74 typedef const _E* const_iterator;
75
Howard Hinnanted569212011-05-26 18:23:59 +000076 _LIBCPP_ALWAYS_INLINE initializer_list() _NOEXCEPT : __begin_(nullptr), __size_(0) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000077
Howard Hinnanted569212011-05-26 18:23:59 +000078 _LIBCPP_ALWAYS_INLINE size_t size() const _NOEXCEPT {return __size_;}
79 _LIBCPP_ALWAYS_INLINE const _E* begin() const _NOEXCEPT {return __begin_;}
80 _LIBCPP_ALWAYS_INLINE const _E* end() const _NOEXCEPT {return __begin_ + __size_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000081};
82
Howard Hinnantfcc59382010-05-28 17:53:59 +000083template<class _E>
84inline _LIBCPP_INLINE_VISIBILITY
85const _E*
Howard Hinnanted569212011-05-26 18:23:59 +000086begin(initializer_list<_E> __il) _NOEXCEPT
Howard Hinnantfcc59382010-05-28 17:53:59 +000087{
88 return __il.begin();
89}
90
91template<class _E>
92inline _LIBCPP_INLINE_VISIBILITY
93const _E*
Howard Hinnanted569212011-05-26 18:23:59 +000094end(initializer_list<_E> __il) _NOEXCEPT
Howard Hinnantfcc59382010-05-28 17:53:59 +000095{
96 return __il.end();
97}
98
Howard Hinnante3e32912011-08-12 21:56:02 +000099#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
100
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000101} // std
102
103#endif // _LIBCPP_INITIALIZER_LIST