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 <cstddef>
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       initializer_list(const_iterator __a, size_type __l)
00061       : _M_array(__a), _M_len(__l) { }
00062 
00063     public:
00064       initializer_list() : _M_array(NULL), _M_len(0) { }
00065 
00066       // Number of elements.
00067       size_type
00068       size() const { return _M_len; }
00069 
00070       // First element.
00071       const_iterator
00072       begin() const { return _M_array; }
00073 
00074       // One past the last element.
00075       const_iterator
00076       end() const { return begin() + size(); }
00077   };
00078 }
00079 
00080 #pragma GCC visibility pop
00081 #endif // C++0x
00082 #endif // _INITIALIZER_LIST