From 36076e63361d7c3d010f673d267793797de122b8 Mon Sep 17 00:00:00 2001 From: astrojhgu Date: Tue, 17 Nov 2009 17:08:23 +0000 Subject: git-svn-id: file:///home/svn/opt_utilities@96 ed2142bd-67ad-457f-ba7c-d818d4011675 --- misc/optvec.hpp | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) (limited to 'misc') 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 +#include namespace opt_utilities { @@ -35,4 +39,78 @@ namespace opt_utilities return dynamic_cast&>(*this); } }; + + template + optvec operator+(const optvec& x1,const optvec& x2) + { + + optvec result(x1); + for(size_t i=0;i!=x1.size();++i) + { + result[i]=result[i]+x2.at(i); + } + return result; + } + + template + optvec operator-(const optvec& x1,const optvec& x2) + { + + optvec result(x1); + for(size_t i=0;i!=x1.size();++i) + { + result[i]=result[i]-x2.at(i); + } + return result; + } + + template + optvec operator*(const optvec& x1,const optvec& x2) + { + + optvec result(x1); + for(size_t i=0;i!=x1.size();++i) + { + result[i]=result[i]*x2.at(i); + } + return result; + } + + template + optvec operator/(const optvec& x1,const optvec& x2) + { + + optvec result(x1); + for(size_t i=0;i!=x1.size();++i) + { + result[i]=result[i]/x2.at(i); + } + return result; + } + + template + T sum(const optvec& x) + { + T result=0; + for(size_t i=0;i!=x.size();++i) + { + result+=x[i]; + } + return result; + } + + template + bool operator<(const optvec& x1,const optvec& x2) + { + for(size_t i=0;i!=x1.size();++i) + { + if(x1[i]!=x2[i]) + { + return x1[i]