STLMath.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef CASA_STLMATH_H
00029 #define CASA_STLMATH_H
00030
00031
00032 #include <casacore/casa/aips.h>
00033 #include <casacore/casa/BasicMath/Functors.h>
00034 #include <vector>
00035 #include <algorithm>
00036
00037 namespace casacore {
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 void throwContainerSizes (const char* name, size_t l1, size_t l2);
00061
00062
00063 template<typename CONTAINER>
00064 inline void checkContainerSizes (const CONTAINER& left, const CONTAINER& right,
00065 const char* name)
00066 {
00067 if (left.size() != right.size()) {
00068 throwContainerSizes (name, left.size(), right.size());
00069 }
00070 }
00071
00072
00073 template<typename CONTAINER>
00074 inline CONTAINER reversedCasaContainer (const CONTAINER& in)
00075 {
00076 size_t sz = in.size();
00077 CONTAINER out(sz);
00078 for (size_t i=0; i<sz; ++i) {
00079 out[i] = in[sz-i-1];
00080 }
00081 return out;
00082 }
00083
00084
00085 template<class T>
00086 std::vector<T> operator+ (const std::vector<T> &left,
00087 const std::vector<T> &right)
00088 {
00089 checkContainerSizes(left, right, "+");
00090 std::vector<T> result(left.size());
00091 std::transform (left.begin(), left.end(), right.begin(),
00092 result.begin(), std::plus<T>());
00093 return result;
00094 }
00095
00096
00097 template<class T>
00098 std::vector<T> operator/ (const std::vector<T> &left, const T &right)
00099 {
00100 std::vector<T> result(left.size());
00101 std::transform (left.begin(), left.end(), result.begin(),
00102 std::bind2nd(std::divides<T>(), right));
00103 return result;
00104 }
00105
00106
00107
00108 }
00109
00110 #endif