00001 /* $Id: array.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */ 00002 /* 00003 Copyright (C) 2003 - 2012 by David White <dave@whitevine.net> 00004 Part of the Battle for Wesnoth Project http://www.wesnoth.org/ 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY. 00012 00013 See the COPYING file for more details. 00014 */ 00015 00016 /** 00017 * @file 00018 * Template for arrays. 00019 */ 00020 00021 #ifndef ARRAY_HPP_INCLUDED 00022 #define ARRAY_HPP_INCLUDED 00023 00024 #include <algorithm> 00025 00026 namespace util 00027 { 00028 00029 template<typename T,size_t N> 00030 class array 00031 { 00032 public: 00033 typedef T value_type; 00034 typedef T* iterator; 00035 typedef const T* const_iterator; 00036 typedef T& reference; 00037 typedef const T& const_reference; 00038 typedef size_t size_type; 00039 00040 array() {} 00041 array(const T& o) 00042 { 00043 std::fill(begin(),end(),o); 00044 } 00045 00046 iterator begin() { return a; } 00047 iterator end() { return a + N; } 00048 00049 const_iterator begin() const { return a; } 00050 const_iterator end() const { return a + N; } 00051 00052 reference operator[](size_type n) { return a[n]; } 00053 const_reference operator[](size_type n) const { return a[n]; } 00054 00055 reference front() { return a[0]; } 00056 reference back() { return a[N-1]; } 00057 00058 const_reference front() const { return a[0]; } 00059 const_reference back() const { return a[N-1]; } 00060 00061 size_type size() const { return N; } 00062 00063 bool empty() const { return size() == 0; } 00064 00065 T* data() { return a; } 00066 const T* data() const { return a; } 00067 00068 private: 00069 T a[N]; 00070 }; 00071 00072 } // end namespace util 00073 00074 #endif 00075
| Generated by doxygen 1.7.1 on Tue May 22 2012 01:03:40 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |