aboutsummaryrefslogtreecommitdiffstats
path: root/misc
diff options
context:
space:
mode:
authorastrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675>2009-11-17 17:08:23 +0000
committerastrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675>2009-11-17 17:08:23 +0000
commit36076e63361d7c3d010f673d267793797de122b8 (patch)
tree70a0df4cdfca1d1a4fb0d9f1d67c981aad12ed86 /misc
parentaa2167fb6ab9ea40278757964d2f00d4b24b8362 (diff)
downloadopt-utilities-36076e63361d7c3d010f673d267793797de122b8.tar.bz2
git-svn-id: file:///home/svn/opt_utilities@96 ed2142bd-67ad-457f-ba7c-d818d4011675
Diffstat (limited to 'misc')
-rw-r--r--misc/optvec.hpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/misc/optvec.hpp b/misc/optvec.hpp
index d23934c..d950c5f 100644
--- a/misc/optvec.hpp
+++ b/misc/optvec.hpp
@@ -1,4 +1,8 @@
+#ifndef OPTVEC_HPP
+#define OPTVEC_HPP
+
#include <vector>
+#include <cassert>
namespace opt_utilities
{
@@ -35,4 +39,78 @@ namespace opt_utilities
return dynamic_cast<const std::vector<T>&>(*this);
}
};
+
+ template<typename T>
+ optvec<T> operator+(const optvec<T>& x1,const optvec<T>& x2)
+ {
+
+ optvec<T> result(x1);
+ for(size_t i=0;i!=x1.size();++i)
+ {
+ result[i]=result[i]+x2.at(i);
+ }
+ return result;
+ }
+
+ template<typename T>
+ optvec<T> operator-(const optvec<T>& x1,const optvec<T>& x2)
+ {
+
+ optvec<T> result(x1);
+ for(size_t i=0;i!=x1.size();++i)
+ {
+ result[i]=result[i]-x2.at(i);
+ }
+ return result;
+ }
+
+ template<typename T>
+ optvec<T> operator*(const optvec<T>& x1,const optvec<T>& x2)
+ {
+
+ optvec<T> result(x1);
+ for(size_t i=0;i!=x1.size();++i)
+ {
+ result[i]=result[i]*x2.at(i);
+ }
+ return result;
+ }
+
+ template<typename T>
+ optvec<T> operator/(const optvec<T>& x1,const optvec<T>& x2)
+ {
+
+ optvec<T> result(x1);
+ for(size_t i=0;i!=x1.size();++i)
+ {
+ result[i]=result[i]/x2.at(i);
+ }
+ return result;
+ }
+
+ template <typename T>
+ T sum(const optvec<T>& x)
+ {
+ T result=0;
+ for(size_t i=0;i!=x.size();++i)
+ {
+ result+=x[i];
+ }
+ return result;
+ }
+
+ template<typename T>
+ bool operator<(const optvec<T>& x1,const optvec<T>& x2)
+ {
+ for(size_t i=0;i!=x1.size();++i)
+ {
+ if(x1[i]!=x2[i])
+ {
+ return x1[i]<x2[i];
+ }
+ }
+ return false;
+ }
+
};
+#endif