fixedarray.hh

Go to the documentation of this file.
00001 #ifndef DUNE_FIXEDARRAY_HH
00002 #define DUNE_FIXEDARRAY_HH
00003 
00009 #include<iostream>
00010 #include<iomanip>
00011 #include<string>
00012 
00013 // Include system implementation of array class if present
00014 #ifdef HAVE_ARRAY
00015 #include <array>
00016 #endif
00017 #ifdef HAVE_TR1_ARRAY
00018 #include <tr1/array>
00019 #endif
00020 
00021 
00022 namespace Dune 
00023 {
00029 #ifdef HAVE_ARRAY
00030     using std::array;
00031 #elif defined HAVE_TR1_ARRAY
00032     using std::tr1::array;
00033 #else
00034 
00038   template<class T, int N>
00039   class array {
00040   public:
00041 
00043       typedef T                                       value_type;
00044 
00046       typedef value_type&                             reference;
00047 
00049       typedef const value_type&                       const_reference;
00050 
00052       typedef value_type*                             iterator;
00053 
00055       typedef const value_type*                       const_iterator;
00056 
00058       typedef std::size_t                             size_type;
00059 
00061       typedef std::ptrdiff_t                          difference_type;
00062 
00064       typedef std::reverse_iterator<iterator>         reverse_iterator;
00065 
00067       typedef std::reverse_iterator<const_iterator>   const_reverse_iterator;
00068 
00070       array () {}
00071       
00073       size_type size() const {return N;}
00074 
00076       array<T,N>& operator= (const T& t)
00077       {
00078           for (int i=0; i<N; i++) a[i]=t;
00079           return (*this);
00080       }
00081         
00083       void assign(const T& t)
00084       {
00085           for (int i=0; i<N; i++) a[i]=t;
00086       }
00087 
00089       reference operator[] (size_type i)
00090       {
00091           return a[i];
00092       }
00093 
00095       const_reference operator[] (size_type i) const
00096       {
00097           return a[i];
00098       }
00099 
00100   protected:
00101       T a[(N > 0) ? N : 1];
00102   };
00103 #endif
00105     template <class T, int N>
00106     inline std::ostream& operator<< (std::ostream& s, array<T,N> e)
00107     {
00108         s << "[";
00109         for (int i=0; i<N-1; i++) s << e[i] << ",";
00110         s << e[N-1] << "]";
00111         return s;
00112     }
00113 
00116 } // end namespace Dune
00117 
00118 #endif

Generated on Sun Nov 15 22:28:12 2009 for dune-common by  doxygen 1.5.6