Teuchos - Trilinos Tools Package Version of the Day
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 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 #ifndef TEUCHOS_TUPLE_HPP
00043 #define TEUCHOS_TUPLE_HPP
00044 
00045 
00046 #include "Teuchos_ArrayView.hpp"
00047 
00048 
00049 namespace Teuchos {
00050 
00051 
00066 template<typename T, int N>
00067 class Tuple : public ArrayView<T> {
00068 public:
00069   
00072   inline Tuple();
00073   
00076   Tuple( const Tuple<T,N> &t );
00077   
00080   Tuple<T,N>& operator=( const Tuple<T,N> &t );
00081 
00082 private:
00083 
00084   T array_[N];
00085 
00086 };
00087 
00088 
00093 template<typename T> inline
00094 Tuple<T,1> tuple(const T& a);
00095 
00096                       
00101 template<typename T> inline
00102 Tuple<T,2> tuple(const T& a, const T& b);
00103 
00104 
00109 template<typename T> inline
00110 Tuple<T,3> tuple(const T& a, const T& b, const T& c);
00111 
00112 
00117 template<typename T> inline
00118 Tuple<T,4> tuple(const T& a, const T& b, const T& c, const T& d);
00119 
00120 
00125 template<typename T> inline
00126 Tuple<T,5> tuple(const T& a, const T& b, const T& c, const T& d, const T& e);
00127 
00128 
00133 template<typename T> inline
00134 Tuple<T,6> tuple(const T& a, const T& b, const T& c, const T& d, const T& e,
00135   const T& f);
00136 
00137 
00142 template<typename T> inline
00143 Tuple<T,7> tuple(const T& a, const T& b, const T& c, const T& d, const T& e,
00144   const T& f, const T& g);
00145 
00146 
00151 template<typename T> inline
00152 Tuple<T,8> tuple(const T& a, const T& b, const T& c, const T& d, const T& e,
00153   const T& f, const T& g, const T& h);
00154 
00155 
00160 template<typename T> inline
00161 Tuple<T,9> tuple(const T& a, const T& b, const T& c, const T& d, const T& e,
00162   const T& f, const T& g, const T& h, const T& i);
00163 
00164 
00169 template<typename T> inline
00170 Tuple<T,10> tuple(const T& a, const T& b, const T& c, const T& d, const T& e,
00171   const T& f, const T& g, const T& h, const T& i, const T& j);
00172 
00173 
00178 template<typename T> inline
00179 Tuple<T,11> tuple(const T& a, const T& b, const T& c, const T& d, const T& e,
00180   const T& f, const T& g, const T& h, const T& i, const T& j, const T& k);
00181 
00182 
00187 template<typename T> inline
00188 Tuple<T,12> tuple(const T& a, const T& b, const T& c, const T& d, const T& e,
00189   const T& f, const T& g, const T& h, const T& i, const T& j, const T& k,
00190   const T& l);
00191 
00192 
00197 template<typename T> inline
00198 Tuple<T,13> tuple(const T& a, const T& b, const T& c, const T& d, const T& e,
00199   const T& f, const T& g, const T& h, const T& i, const T& j, const T& k,
00200   const T& l, const T& m);
00201 
00202 
00207 template<typename T> inline
00208 Tuple<T,14> tuple(const T& a, const T& b, const T& c, const T& d, const T& e,
00209   const T& f, const T& g, const T& h, const T& i, const T& j, const T& k,
00210   const T& l, const T& m, const T& n);
00211 
00212 
00217 template<typename T> inline
00218 Tuple<T,15> tuple(const T& a, const T& b, const T& c, const T& d, const T& e,
00219   const T& f, const T& g, const T& h, const T& i, const T& j, const T& k,
00220   const T& l, const T& m, const T& n, const T& o);
00221 
00222 
00223 //
00224 // Implementations
00225 //
00226 
00227 
00228 template<typename T, int N> inline
00229 Tuple<T,N>::Tuple()
00230 :ArrayView<T>() // To get rid of warnings!
00231 {
00232   ArrayView<T>::operator=(ArrayView<T>(&array_[0],N));
00233 }
00234 
00235 
00236 template<typename T, int N>
00237 Tuple<T,N>::Tuple( const Tuple<T,N> &t )
00238 :ArrayView<T>() // To get rid of warnings!
00239 {
00240   for( int i = 0; i < N; ++i )
00241     array_[i] = t[i];
00242   // Above, this loop with static N should allow the compiler to unroll this
00243   // entire loop!
00244   ArrayView<T>::operator=(ArrayView<T>(&array_[0],N));
00245 }
00246 
00247 
00248 template<typename T, int N>
00249 Tuple<T,N>& Tuple<T,N>::operator=( const Tuple<T,N> &t )
00250 {
00251   for( int i = 0; i < N; ++i )
00252     array_[i] = t[i];
00253   // Above, this loop with static N should allow the compiler to unroll this
00254   // entire loop!
00255   return *this;
00256 }
00257 
00258 
00259 } // end namespace Teuchos
00260 
00261 
00262 //
00263 // Nonmember function implementations
00264 //
00265 
00266 
00267 template<typename T> inline
00268 Teuchos::Tuple<T,1>
00269 Teuchos::tuple(const T& a)
00270 {
00271   Tuple<T,1> rtn;
00272   rtn[0] = a;
00273   return rtn;
00274 }
00275 
00276 
00277 template<typename T> inline
00278 Teuchos::Tuple<T,2>
00279 Teuchos::tuple(const T& a, const T& b)
00280 {
00281   Tuple<T,2> rtn;
00282   rtn[0] = a;
00283   rtn[1] = b;
00284   return rtn;
00285 }
00286 
00287 
00288 template<typename T> inline
00289 Teuchos::Tuple<T,3>
00290 Teuchos::tuple(const T& a, const T& b, const T& c)
00291 {
00292   Tuple<T,3> rtn;
00293   rtn[0] = a;
00294   rtn[1] = b;
00295   rtn[2] = c;
00296   return rtn;
00297 }
00298 
00299 
00300 template<typename T> inline
00301 Teuchos::Tuple<T,4>
00302 Teuchos::tuple(const T& a, const T& b, const T& c, const T& d)
00303 {
00304   Tuple<T,4> rtn;;
00305   rtn[0] = a;
00306   rtn[1] = b;
00307   rtn[2] = c;
00308   rtn[3] = d;
00309   return rtn;
00310 }
00311 
00312 
00313 template<typename T> inline
00314 Teuchos::Tuple<T,5>
00315 Teuchos::tuple(const T& a, const T& b, const T& c, const T& d, const T& e)
00316 {
00317   Tuple<T,5> rtn;
00318   rtn[0] = a;
00319   rtn[1] = b;
00320   rtn[2] = c;
00321   rtn[3] = d;
00322   rtn[4] = e;
00323   return rtn;
00324 }
00325 
00326 
00327 template<typename T> inline
00328 Teuchos::Tuple<T,6>
00329 Teuchos::tuple(const T& a, const T& b, const T& c, const T& d, const T& e,
00330   const T& f)
00331 {
00332   Tuple<T,6> rtn;
00333   rtn[0] = a;
00334   rtn[1] = b;
00335   rtn[2] = c;
00336   rtn[3] = d;
00337   rtn[4] = e;
00338   rtn[5] = f;
00339   return rtn;
00340 }
00341 
00342 
00343 template<typename T> inline
00344 Teuchos::Tuple<T,7>
00345 Teuchos::tuple(const T& a, const T& b, const T& c, const T& d, const T& e,
00346   const T& f, const T& g)
00347 {
00348   Tuple<T,7> rtn;
00349   rtn[0] = a;
00350   rtn[1] = b;
00351   rtn[2] = c;
00352   rtn[3] = d;
00353   rtn[4] = e;
00354   rtn[5] = f;
00355   rtn[6] = g;
00356   return rtn;
00357 }
00358 
00359 
00360 template<typename T> inline
00361 Teuchos::Tuple<T,8>
00362 Teuchos::tuple(const T& a, const T& b, const T& c, const T& d, const T& e,
00363   const T& f, const T& g, const T& h)
00364 {
00365   Tuple<T,8> rtn;
00366   rtn[0] = a;
00367   rtn[1] = b;
00368   rtn[2] = c;
00369   rtn[3] = d;
00370   rtn[4] = e;
00371   rtn[5] = f;
00372   rtn[6] = g;
00373   rtn[7] = h;
00374   return rtn;
00375 }
00376 
00377 
00378 template<typename T> inline
00379 Teuchos::Tuple<T,9>
00380 Teuchos::tuple(const T& a, const T& b, const T& c, const T& d, const T& e,
00381   const T& f, const T& g, const T& h, const T& i)
00382 {
00383   Tuple<T,9> rtn;
00384   rtn[0] = a;
00385   rtn[1] = b;
00386   rtn[2] = c;
00387   rtn[3] = d;
00388   rtn[4] = e;
00389   rtn[5] = f;
00390   rtn[6] = g;
00391   rtn[7] = h;
00392   rtn[8] = i;
00393   return rtn;
00394 }
00395 
00396 
00397 template<typename T> inline
00398 Teuchos::Tuple<T,10>
00399 Teuchos::tuple(const T& a, const T& b, const T& c, const T& d, const T& e,
00400   const T& f, const T& g, const T& h, const T& i, const T& j)
00401 {
00402   Tuple<T,10> rtn;
00403   rtn[0] = a;
00404   rtn[1] = b;
00405   rtn[2] = c;
00406   rtn[3] = d;
00407   rtn[4] = e;
00408   rtn[5] = f;
00409   rtn[6] = g;
00410   rtn[7] = h;
00411   rtn[8] = i;
00412   rtn[9] = j;
00413   return rtn;
00414 }
00415 
00416 
00417 template<typename T> inline
00418 Teuchos::Tuple<T,11>
00419 Teuchos::tuple(const T& a, const T& b, const T& c, const T& d, const T& e,
00420   const T& f, const T& g, const T& h, const T& i, const T& j, const T& k)
00421 {
00422   Tuple<T,11> rtn;
00423   rtn[0] = a;
00424   rtn[1] = b;
00425   rtn[2] = c;
00426   rtn[3] = d;
00427   rtn[4] = e;
00428   rtn[5] = f;
00429   rtn[6] = g;
00430   rtn[7] = h;
00431   rtn[8] = i;
00432   rtn[9] = j;
00433   rtn[10] = k;
00434   return rtn;
00435 }
00436 
00437 template<typename T> inline
00438 Teuchos::Tuple<T,12>
00439 Teuchos::tuple(const T& a, const T& b, const T& c, const T& d, const T& e,
00440   const T& f, const T& g, const T& h, const T& i, const T& j, const T& k,
00441   const T& l)
00442 {
00443   Tuple<T,12> rtn;
00444   rtn[0] = a;
00445   rtn[1] = b;
00446   rtn[2] = c;
00447   rtn[3] = d;
00448   rtn[4] = e;
00449   rtn[5] = f;
00450   rtn[6] = g;
00451   rtn[7] = h;
00452   rtn[8] = i;
00453   rtn[9] = j;
00454   rtn[10] = k;
00455   rtn[11] = l;
00456   return rtn;
00457 }
00458 
00459 template<typename T> inline
00460 Teuchos::Tuple<T,13>
00461 Teuchos::tuple(const T& a, const T& b, const T& c, const T& d, const T& e,
00462   const T& f, const T& g, const T& h, const T& i, const T& j, const T& k,
00463   const T& l, const T& m)
00464 {
00465   Tuple<T,13> rtn;
00466   rtn[0] = a;
00467   rtn[1] = b;
00468   rtn[2] = c;
00469   rtn[3] = d;
00470   rtn[4] = e;
00471   rtn[5] = f;
00472   rtn[6] = g;
00473   rtn[7] = h;
00474   rtn[8] = i;
00475   rtn[9] = j;
00476   rtn[10] = k;
00477   rtn[11] = l;
00478   rtn[12] = m;
00479   return rtn;
00480 }
00481 
00482 
00483 template<typename T> inline
00484 Teuchos::Tuple<T,14>
00485 Teuchos::tuple(const T& a, const T& b, const T& c, const T& d, const T& e,
00486   const T& f, const T& g, const T& h, const T& i, const T& j, const T& k,
00487   const T& l, const T& m, const T& n)
00488 {
00489   Tuple<T,14> rtn;
00490   rtn[0] = a;
00491   rtn[1] = b;
00492   rtn[2] = c;
00493   rtn[3] = d;
00494   rtn[4] = e;
00495   rtn[5] = f;
00496   rtn[6] = g;
00497   rtn[7] = h;
00498   rtn[8] = i;
00499   rtn[9] = j;
00500   rtn[10] = k;
00501   rtn[11] = l;
00502   rtn[12] = m;
00503   rtn[13] = n;
00504   return rtn;
00505 }
00506 
00507 
00508 template<typename T> inline
00509 Teuchos::Tuple<T,15>
00510 Teuchos::tuple(const T& a, const T& b, const T& c, const T& d, const T& e,
00511   const T& f, const T& g, const T& h, const T& i, const T& j, const T& k,
00512   const T& l, const T& m, const T& n, const T& o)
00513 {
00514   Tuple<T,15> rtn;
00515   rtn[0] = a;
00516   rtn[1] = b;
00517   rtn[2] = c;
00518   rtn[3] = d;
00519   rtn[4] = e;
00520   rtn[5] = f;
00521   rtn[6] = g;
00522   rtn[7] = h;
00523   rtn[8] = i;
00524   rtn[9] = j;
00525   rtn[10] = k;
00526   rtn[11] = l;
00527   rtn[12] = m;
00528   rtn[13] = n;
00529   rtn[14] = o;
00530   return rtn;
00531 }
00532 
00533 
00534 #endif  // TEUCHOS_TUPLE_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines