libstdc++
initializer_list
Go to the documentation of this file.
00001 // std::initializer_list support -*- C++ -*-
00002 
00003 // Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
00004 //
00005 // This file is part of GCC.
00006 //
00007 // GCC is free software; you can redistribute it and/or modify
00008 // it under the terms of the GNU General Public License as published by
00009 // the Free Software Foundation; either version 3, or (at your option)
00010 // any later version.
00011 //
00012 // GCC is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // Under Section 7 of GPL version 3, you are granted additional
00018 // permissions described in the GCC Runtime Library Exception, version
00019 // 3.1, as published by the Free Software Foundation.
00020 
00021 // You should have received a copy of the GNU General Public License and
00022 // a copy of the GCC Runtime Library Exception along with this program;
00023 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00024 // <http://www.gnu.org/licenses/>.
00025 
00026 /** @file initializer_list
00027  *  This is a Standard C++ Library header.
00028  */
00029 
00030 #ifndef _INITIALIZER_LIST
00031 #define _INITIALIZER_LIST
00032 
00033 #pragma GCC system_header
00034 
00035 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00036 
00037 #pragma GCC visibility push(default)
00038 
00039 #include <bits/c++config.h>
00040 
00041 namespace std
00042 {
00043   /// initializer_list
00044   template<class _E>
00045     class initializer_list
00046     {
00047     public:
00048       typedef _E        value_type;
00049       typedef const _E&     reference;
00050       typedef const _E&     const_reference;
00051       typedef size_t        size_type;
00052       typedef const _E*     iterator;
00053       typedef const _E*     const_iterator;
00054 
00055     private:
00056       iterator          _M_array;
00057       size_type         _M_len;
00058 
00059       // The compiler can call a private constructor.
00060       constexpr initializer_list(const_iterator __a, size_type __l)
00061       : _M_array(__a), _M_len(__l) { }
00062 
00063     public:
00064       constexpr initializer_list() : _M_array(0), _M_len(0) { }
00065 
00066       // Number of elements.
00067       constexpr size_type
00068       size() { return _M_len; }
00069 
00070       // First element.
00071       constexpr const_iterator
00072       begin() { return _M_array; }
00073 
00074       // One past the last element.
00075       constexpr const_iterator
00076       end() { return begin() + size(); }
00077   };
00078 
00079   /**
00080    *  @brief  Return an iterator pointing to the first element of
00081    *          the initilizer_list.
00082    *  @param  il  Initializer list.
00083    */
00084   template<class _Tp>
00085     constexpr const _Tp*
00086     begin(initializer_list<_Tp> __ils)
00087     { return __ils.begin(); }
00088 
00089   /**
00090    *  @brief  Return an iterator pointing to one past the last element
00091    *          of the initilizer_list.
00092    *  @param  il  Initializer list.
00093    */
00094   template<class _Tp>
00095     constexpr const _Tp*
00096     end(initializer_list<_Tp> __ils)
00097     { return __ils.end(); }
00098 }
00099 
00100 #pragma GCC visibility pop
00101 #endif // C++0x
00102 #endif // _INITIALIZER_LIST