Teuchos_Tuple.hpp

00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //                    Teuchos: Common Tools Package
00005 //                 Copyright (2004) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #ifndef TEUCHOS_TUPLE_HPP
00030 #define TEUCHOS_TUPLE_HPP
00031 
00032 
00033 #include "Teuchos_ArrayView.hpp"
00034 
00035 
00036 namespace Teuchos {
00037 
00038 
00053 template<typename T, int N>
00054 class Tuple : public ArrayView<T> {
00055 public:
00056   
00059   inline Tuple();
00060   
00063   Tuple( const Tuple<T,N> &t );
00064   
00067   Tuple<T,N>& operator=( const Tuple<T,N> &t );
00068 
00069 private:
00070 
00071   T array_[N];
00072 
00073 };
00074 
00075 
00080 template<typename T> inline
00081 Tuple<T,1> tuple(const T& a);
00082 
00083                       
00088 template<typename T> inline
00089 Tuple<T,2> tuple(const T& a, const T& b);
00090 
00091 
00096 template<typename T> inline
00097 Tuple<T,3> tuple(const T& a, const T& b, const T& c);
00098 
00099 
00104 template<typename T> inline
00105 Tuple<T,4> tuple(const T& a, const T& b, const T& c, const T& d);
00106 
00107 
00112 template<typename T> inline
00113 Tuple<T,5> tuple(const T& a, const T& b, const T& c, const T& d, const T& e);
00114 
00115 
00120 template<typename T> inline
00121 Tuple<T,6> tuple(const T& a, const T& b, const T& c, const T& d, const T& e,
00122   const T& f);
00123 
00124 
00129 template<typename T> inline
00130 Tuple<T,7> tuple(const T& a, const T& b, const T& c, const T& d, const T& e,
00131   const T& f, const T& g);
00132 
00133 
00138 template<typename T> inline
00139 Tuple<T,8> tuple(const T& a, const T& b, const T& c, const T& d, const T& e,
00140   const T& f, const T& g, const T& h);
00141 
00142 
00147 template<typename T> inline
00148 Tuple<T,9> tuple(const T& a, const T& b, const T& c, const T& d, const T& e,
00149   const T& f, const T& g, const T& h, const T& i);
00150 
00151 
00156 template<typename T> inline
00157 Tuple<T,10> tuple(const T& a, const T& b, const T& c, const T& d, const T& e,
00158   const T& f, const T& g, const T& h, const T& i, const T& j);
00159 
00160 
00161 //
00162 // Implementations
00163 //
00164 
00165 
00166 template<typename T, int N> inline
00167 Tuple<T,N>::Tuple()
00168   : ArrayView<T>(&array_[0],N)
00169 {}
00170 
00171 
00172 template<typename T, int N>
00173 Tuple<T,N>::Tuple( const Tuple<T,N> &t )
00174   : ArrayView<T>(&array_[0],N)
00175 {
00176   for( int i = 0; i < N; ++i )
00177     array_[i] = t[i];
00178   // Above, this loop with static N should allow the compiler to unroll this
00179   // entire loop!
00180 }
00181 
00182 
00183 template<typename T, int N>
00184 Tuple<T,N>& Tuple<T,N>::operator=( const Tuple<T,N> &t )
00185 {
00186   for( int i = 0; i < N; ++i )
00187     array_[i] = t[i];
00188   // Above, this loop with static N should allow the compiler to unroll this
00189   // entire loop!
00190   return *this;
00191 }
00192 
00193 
00194 } // end namespace Teuchos
00195 
00196 
00197 //
00198 // Nonmember function implementations
00199 //
00200 
00201 
00202 template<typename T> inline
00203 Teuchos::Tuple<T,1>
00204 Teuchos::tuple(const T& a)
00205 {
00206   Tuple<T,1> rtn;
00207   rtn[0] = a;
00208   return rtn;
00209 }
00210 
00211 
00212 template<typename T> inline
00213 Teuchos::Tuple<T,2>
00214 Teuchos::tuple(const T& a, const T& b)
00215 {
00216   Tuple<T,2> rtn;
00217   rtn[0] = a;
00218   rtn[1] = b;
00219   return rtn;
00220 }
00221 
00222 
00223 template<typename T> inline
00224 Teuchos::Tuple<T,3>
00225 Teuchos::tuple(const T& a, const T& b, const T& c)
00226 {
00227   Tuple<T,3> rtn;
00228   rtn[0] = a;
00229   rtn[1] = b;
00230   rtn[2] = c;
00231   return rtn;
00232 }
00233 
00234 
00235 template<typename T> inline
00236 Teuchos::Tuple<T,4>
00237 Teuchos::tuple(const T& a, const T& b, const T& c, const T& d)
00238 {
00239   Tuple<T,4> rtn;;
00240   rtn[0] = a;
00241   rtn[1] = b;
00242   rtn[2] = c;
00243   rtn[3] = d;
00244   return rtn;
00245 }
00246 
00247 
00248 template<typename T> inline
00249 Teuchos::Tuple<T,5>
00250 Teuchos::tuple(const T& a, const T& b, const T& c, const T& d, const T& e)
00251 {
00252   Tuple<T,5> rtn;
00253   rtn[0] = a;
00254   rtn[1] = b;
00255   rtn[2] = c;
00256   rtn[3] = d;
00257   rtn[4] = e;
00258   return rtn;
00259 }
00260 
00261 
00262 template<typename T> inline
00263 Teuchos::Tuple<T,6>
00264 Teuchos::tuple(const T& a, const T& b, const T& c, const T& d, const T& e,
00265   const T& f)
00266 {
00267   Tuple<T,6> rtn;
00268   rtn[0] = a;
00269   rtn[1] = b;
00270   rtn[2] = c;
00271   rtn[3] = d;
00272   rtn[4] = e;
00273   rtn[5] = f;
00274   return rtn;
00275 }
00276 
00277 
00278 template<typename T> inline
00279 Teuchos::Tuple<T,7>
00280 Teuchos::tuple(const T& a, const T& b, const T& c, const T& d, const T& e,
00281   const T& f, const T& g)
00282 {
00283   Tuple<T,7> rtn;
00284   rtn[0] = a;
00285   rtn[1] = b;
00286   rtn[2] = c;
00287   rtn[3] = d;
00288   rtn[4] = e;
00289   rtn[5] = f;
00290   rtn[6] = g;
00291   return rtn;
00292 }
00293 
00294 
00295 template<typename T> inline
00296 Teuchos::Tuple<T,8>
00297 Teuchos::tuple(const T& a, const T& b, const T& c, const T& d, const T& e,
00298   const T& f, const T& g, const T& h)
00299 {
00300   Tuple<T,8> rtn;
00301   rtn[0] = a;
00302   rtn[1] = b;
00303   rtn[2] = c;
00304   rtn[3] = d;
00305   rtn[4] = e;
00306   rtn[5] = f;
00307   rtn[6] = g;
00308   rtn[7] = h;
00309   return rtn;
00310 }
00311 
00312 
00313 template<typename T> inline
00314 Teuchos::Tuple<T,9>
00315 Teuchos::tuple(const T& a, const T& b, const T& c, const T& d, const T& e,
00316   const T& f, const T& g, const T& h, const T& i)
00317 {
00318   Tuple<T,9> rtn;
00319   rtn[0] = a;
00320   rtn[1] = b;
00321   rtn[2] = c;
00322   rtn[3] = d;
00323   rtn[4] = e;
00324   rtn[5] = f;
00325   rtn[6] = g;
00326   rtn[7] = h;
00327   rtn[8] = i;
00328   return rtn;
00329 }
00330 
00331 
00332 template<typename T> inline
00333 Teuchos::Tuple<T,10>
00334 Teuchos::tuple(const T& a, const T& b, const T& c, const T& d, const T& e,
00335   const T& f, const T& g, const T& h, const T& i, const T& j)
00336 {
00337   Tuple<T,10> rtn;
00338   rtn[0] = a;
00339   rtn[1] = b;
00340   rtn[2] = c;
00341   rtn[3] = d;
00342   rtn[4] = e;
00343   rtn[5] = f;
00344   rtn[6] = g;
00345   rtn[7] = h;
00346   rtn[8] = i;
00347   rtn[9] = j;
00348   return rtn;
00349 }
00350 
00351 
00352 #endif  // TEUCHOS_TUPLE_HPP

Generated on Wed May 12 21:40:33 2010 for Teuchos - Trilinos Tools Package by  doxygen 1.4.7