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