aboutsummaryrefslogtreecommitdiffstats
path: root/misc
diff options
context:
space:
mode:
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