1*38fd1498Szrj// std::initializer_list support -*- C++ -*- 2*38fd1498Szrj 3*38fd1498Szrj// Copyright (C) 2008-2018 Free Software Foundation, Inc. 4*38fd1498Szrj// 5*38fd1498Szrj// This file is part of GCC. 6*38fd1498Szrj// 7*38fd1498Szrj// GCC is free software; you can redistribute it and/or modify 8*38fd1498Szrj// it under the terms of the GNU General Public License as published by 9*38fd1498Szrj// the Free Software Foundation; either version 3, or (at your option) 10*38fd1498Szrj// any later version. 11*38fd1498Szrj// 12*38fd1498Szrj// GCC is distributed in the hope that it will be useful, 13*38fd1498Szrj// but WITHOUT ANY WARRANTY; without even the implied warranty of 14*38fd1498Szrj// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*38fd1498Szrj// GNU General Public License for more details. 16*38fd1498Szrj// 17*38fd1498Szrj// Under Section 7 of GPL version 3, you are granted additional 18*38fd1498Szrj// permissions described in the GCC Runtime Library Exception, version 19*38fd1498Szrj// 3.1, as published by the Free Software Foundation. 20*38fd1498Szrj 21*38fd1498Szrj// You should have received a copy of the GNU General Public License and 22*38fd1498Szrj// a copy of the GCC Runtime Library Exception along with this program; 23*38fd1498Szrj// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 24*38fd1498Szrj// <http://www.gnu.org/licenses/>. 25*38fd1498Szrj 26*38fd1498Szrj/** @file initializer_list 27*38fd1498Szrj * This is a Standard C++ Library header. 28*38fd1498Szrj */ 29*38fd1498Szrj 30*38fd1498Szrj#ifndef _INITIALIZER_LIST 31*38fd1498Szrj#define _INITIALIZER_LIST 32*38fd1498Szrj 33*38fd1498Szrj#pragma GCC system_header 34*38fd1498Szrj 35*38fd1498Szrj#if __cplusplus < 201103L 36*38fd1498Szrj# include <bits/c++0x_warning.h> 37*38fd1498Szrj#else // C++0x 38*38fd1498Szrj 39*38fd1498Szrj#pragma GCC visibility push(default) 40*38fd1498Szrj 41*38fd1498Szrj#include <bits/c++config.h> 42*38fd1498Szrj 43*38fd1498Szrjnamespace std 44*38fd1498Szrj{ 45*38fd1498Szrj /// initializer_list 46*38fd1498Szrj template<class _E> 47*38fd1498Szrj class initializer_list 48*38fd1498Szrj { 49*38fd1498Szrj public: 50*38fd1498Szrj typedef _E value_type; 51*38fd1498Szrj typedef const _E& reference; 52*38fd1498Szrj typedef const _E& const_reference; 53*38fd1498Szrj typedef size_t size_type; 54*38fd1498Szrj typedef const _E* iterator; 55*38fd1498Szrj typedef const _E* const_iterator; 56*38fd1498Szrj 57*38fd1498Szrj private: 58*38fd1498Szrj iterator _M_array; 59*38fd1498Szrj size_type _M_len; 60*38fd1498Szrj 61*38fd1498Szrj // The compiler can call a private constructor. 62*38fd1498Szrj constexpr initializer_list(const_iterator __a, size_type __l) 63*38fd1498Szrj : _M_array(__a), _M_len(__l) { } 64*38fd1498Szrj 65*38fd1498Szrj public: 66*38fd1498Szrj constexpr initializer_list() noexcept 67*38fd1498Szrj : _M_array(0), _M_len(0) { } 68*38fd1498Szrj 69*38fd1498Szrj // Number of elements. 70*38fd1498Szrj constexpr size_type 71*38fd1498Szrj size() const noexcept { return _M_len; } 72*38fd1498Szrj 73*38fd1498Szrj // First element. 74*38fd1498Szrj constexpr const_iterator 75*38fd1498Szrj begin() const noexcept { return _M_array; } 76*38fd1498Szrj 77*38fd1498Szrj // One past the last element. 78*38fd1498Szrj constexpr const_iterator 79*38fd1498Szrj end() const noexcept { return begin() + size(); } 80*38fd1498Szrj }; 81*38fd1498Szrj 82*38fd1498Szrj /** 83*38fd1498Szrj * @brief Return an iterator pointing to the first element of 84*38fd1498Szrj * the initializer_list. 85*38fd1498Szrj * @param __ils Initializer list. 86*38fd1498Szrj */ 87*38fd1498Szrj template<class _Tp> 88*38fd1498Szrj constexpr const _Tp* 89*38fd1498Szrj begin(initializer_list<_Tp> __ils) noexcept 90*38fd1498Szrj { return __ils.begin(); } 91*38fd1498Szrj 92*38fd1498Szrj /** 93*38fd1498Szrj * @brief Return an iterator pointing to one past the last element 94*38fd1498Szrj * of the initializer_list. 95*38fd1498Szrj * @param __ils Initializer list. 96*38fd1498Szrj */ 97*38fd1498Szrj template<class _Tp> 98*38fd1498Szrj constexpr const _Tp* 99*38fd1498Szrj end(initializer_list<_Tp> __ils) noexcept 100*38fd1498Szrj { return __ils.end(); } 101*38fd1498Szrj} 102*38fd1498Szrj 103*38fd1498Szrj#pragma GCC visibility pop 104*38fd1498Szrj 105*38fd1498Szrj#endif // C++11 106*38fd1498Szrj 107*38fd1498Szrj#endif // _INITIALIZER_LIST 108