xvector3.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "xvector2.h"
4 
5 namespace nmx::gsl::vec {
6 
10 template<class TOUT, class TIN>
11 struct IVCalc1 {
20  template<class FN, class... X>
21  inline friend TOUT apply(FN fn, const TIN &v, const X &... x) {
22  TOUT vout(v.size());
23  for (size_t idx = 0; idx < v.size(); idx++) {
24  vout[idx] = fn(v[idx], x[idx]...);
25  }
26  return vout;
27  }
28 
35  inline friend TOUT operator+(const TIN &v1, const TIN &v2) {
36  auto v = apply(std::plus<double>(), v1, v2);
37  return v;
38  }
39 
40  inline friend TOUT operator-(const TIN &v1, const TIN &v2) {
41  return apply(std::minus<double>(), v1, v2);
42  }
43 
44  inline friend TOUT operator*(const TIN &v1, const TIN &v2) {
45  return apply(std::multiplies<double>(), v1, v2);
46  }
47 
48  inline friend TOUT operator/(const TIN &v1, const TIN &v2) {
49  return apply(std::divides<double>(), v1, v2);
50  }
51 
52  inline friend TOUT operator-(const TIN &v) { //
53  return apply(std::negate<double>(), v);
54  }
55 
62  inline friend TOUT operator*(double c, const TIN &v2) {
63  return apply([c](double x) { return x * c; }, v2);
64  }
65 
66  inline friend TOUT operator/(const TIN &v1, double c) {
67  return apply(
68  [c](double x) {
69  Check::error_if(nmx_msg, c == 0.);
70  return x / c;
71  },
72  v1);
73  }
74 };
75 
76 } // namespace nmx::gsl::vec
friend TOUT apply(FN fn, const TIN &v, const X &... x)
apply Anwendung einer Rechenvorschrift auf eine beliebige Anzahl von Vektoren
Definition: xvector3.h:21
static void error_if(const std::string &s, bool arg)
error_if Fehler wenn Bedingung erfüllt ist
Definition: xerror.h:51
friend TOUT operator*(double c, const TIN &v2)
Implementierung der Operatoren *,/.
Definition: xvector3.h:62
#define nmx_msg
Definition: xerror.h:113
friend TOUT operator+(const TIN &v1, const TIN &v2)
Implementierung der Operatoren +,-,*,/.
Definition: xvector3.h:35
friend TOUT operator-(const TIN &v1, const TIN &v2)
Definition: xvector3.h:40
The IVCalc1 class Implementierung von +,-,*,/ (binär)
Definition: xvector3.h:11
friend TOUT operator-(const TIN &v)
Definition: xvector3.h:52
friend TOUT operator/(const TIN &v1, const TIN &v2)
Definition: xvector3.h:48
friend TOUT operator/(const TIN &v1, double c)
Definition: xvector3.h:66
friend TOUT operator*(const TIN &v1, const TIN &v2)
Definition: xvector3.h:44