xref: /freebsd/contrib/llvm-project/libcxx/include/initializer_list (revision 77a1348b3c1cfe8547be49a121b56299a1e18b69)
1// -*- C++ -*-
2//===----------------------- initializer_list -----------------------------===//
3//
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
7//
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
31    initializer_list() noexcept; // constexpr in C++14
32
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
36};
37
38template<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
40
41}  // std
42
43*/
44
45#include <__config>
46#include <cstddef>
47
48#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
49#pragma GCC system_header
50#endif
51
52namespace std  // purposefully not versioned
53{
54
55#ifndef _LIBCPP_CXX03_LANG
56
57template<class _Ep>
58class _LIBCPP_TEMPLATE_VIS initializer_list
59{
60    const _Ep* __begin_;
61    size_t    __size_;
62
63    _LIBCPP_INLINE_VISIBILITY
64    _LIBCPP_CONSTEXPR_AFTER_CXX11
65    initializer_list(const _Ep* __b, size_t __s) _NOEXCEPT
66        : __begin_(__b),
67          __size_(__s)
68        {}
69public:
70    typedef _Ep        value_type;
71    typedef const _Ep& reference;
72    typedef const _Ep& const_reference;
73    typedef size_t    size_type;
74
75    typedef const _Ep* iterator;
76    typedef const _Ep* const_iterator;
77
78    _LIBCPP_INLINE_VISIBILITY
79    _LIBCPP_CONSTEXPR_AFTER_CXX11
80    initializer_list() _NOEXCEPT : __begin_(nullptr), __size_(0) {}
81
82    _LIBCPP_INLINE_VISIBILITY
83    _LIBCPP_CONSTEXPR_AFTER_CXX11
84    size_t    size()  const _NOEXCEPT {return __size_;}
85
86    _LIBCPP_INLINE_VISIBILITY
87    _LIBCPP_CONSTEXPR_AFTER_CXX11
88    const _Ep* begin() const _NOEXCEPT {return __begin_;}
89
90    _LIBCPP_INLINE_VISIBILITY
91    _LIBCPP_CONSTEXPR_AFTER_CXX11
92    const _Ep* end()   const _NOEXCEPT {return __begin_ + __size_;}
93};
94
95template<class _Ep>
96inline _LIBCPP_INLINE_VISIBILITY
97_LIBCPP_CONSTEXPR_AFTER_CXX11
98const _Ep*
99begin(initializer_list<_Ep> __il) _NOEXCEPT
100{
101    return __il.begin();
102}
103
104template<class _Ep>
105inline _LIBCPP_INLINE_VISIBILITY
106_LIBCPP_CONSTEXPR_AFTER_CXX11
107const _Ep*
108end(initializer_list<_Ep> __il) _NOEXCEPT
109{
110    return __il.end();
111}
112
113#endif  // !defined(_LIBCPP_CXX03_LANG)
114
115}  // std
116
117#endif  // _LIBCPP_INITIALIZER_LIST
118