aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetLib
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@gmail.com>2013-01-24 15:10:35 -0500
committerErik Schnetter <schnetter@gmail.com>2013-01-24 15:10:35 -0500
commit3146701470fbcc40afb7495065fd371bf3eec05d (patch)
treed09011f6681637b909c696daf71694367a0c4ce6 /Carpet/CarpetLib
parentbcf3bb045b9b26b4daacf39584e6fc25c03da3ad (diff)
CarpetLib: Implement and correct head, tail, init, last in the vect class
Diffstat (limited to 'Carpet/CarpetLib')
-rw-r--r--Carpet/CarpetLib/src/vect.hh22
1 files changed, 20 insertions, 2 deletions
diff --git a/Carpet/CarpetLib/src/vect.hh b/Carpet/CarpetLib/src/vect.hh
index c5887bfaf..d39327130 100644
--- a/Carpet/CarpetLib/src/vect.hh
+++ b/Carpet/CarpetLib/src/vect.hh
@@ -456,18 +456,36 @@ inline int size (const vect<T,D>& a)
/** Return the first element. */
template<typename T,int D>
-inline int first (const vect<T,D>& a)
+inline T head (const vect<T,D>& a)
{
return a[0];
}
+/** Return all but the first element. */
+template<typename T,int D>
+inline vect<T,D-1> tail (const vect<T,D>& a)
+{
+ vect<T,D-1> r;
+ for (int d=0; d<D-1; ++d) r[d]=a[d+1];
+ return r;
+}
+
/** Return the last element. */
template<typename T,int D>
-inline int last (const vect<T,D>& a)
+inline T last (const vect<T,D>& a)
{
return a[D-1];
}
+/** Return all but the last element. */
+template<typename T,int D>
+inline vect<T,D-1> init (const vect<T,D>& a)
+{
+ vect<T,D-1> r;
+ for (int d=0; d<D-1; ++d) r[d]=a[d];
+ return r;
+}
+
/** Return the index of the first maximum element. */
template<typename T,int D>
inline int maxloc (const vect<T,D>& a)