xvector2.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "xerror.h"
4 #include "xvector1.h"
5 #include <type_traits>
6 
7 namespace nmx::gsl::vec {
8 
13 template<class T>
14 class IVCalc : public IGslContainer<T, gsl_vector, 2>
15 {
17 
18 protected:
25  template<class X, class FN>
26  inline T &apply_fn(const X &v, FN fn) {
27  if constexpr (std::is_same_v<X, double>) {
28  fn(gsl(), v); //z.B. gsl_vector_add_constant( , v)
29  } else {
30  fn(gsl(), v.gsl()); //z.B. gsl_vector_add( , v)
31  }
32  return static_cast<T &>(*this);
33  }
34 
35 public:
41  inline T &operator+=(const T &v) { //
42  return apply_fn(v, gsl_vector_add);
43  }
44  inline T &operator-=(const T &v) { //
45  return apply_fn(v, gsl_vector_sub);
46  }
47  inline T &operator*=(const T &v) { //
48  return apply_fn(v, gsl_vector_mul);
49  }
50  inline T &operator/=(const T &v) { //
51  return apply_fn(v, gsl_vector_div);
52  }
53 
59  inline T &operator+=(double x) { //
60  return apply_fn(x, gsl_vector_add_constant);
61  }
62  inline T &operator-=(double x) { //
63  return apply_fn(-x, gsl_vector_add_constant);
64  }
65  inline T &operator*=(double x) { //
66  return apply_fn(x, gsl_vector_scale);
67  }
68 
74  inline T &operator/=(double x) {
75  Check::error_if(nmx_msg, x == 0.0);
76  gsl_vector_scale(gsl(), 1 / x);
77  return static_cast<T &>(*this);
78  }
79 }; //IVCalc
80 
81 } // namespace nmx::gsl::vec
The IVCalc struct Komponente implementiert Operatoren +=,-=,*=,/=.
Definition: xvector2.h:14
T & operator+=(double x)
Implementierung der Operatoren +=,-=,*=.
Definition: xvector2.h:59
T & operator+=(const T &v)
Implementierung der Operatoren +=,-=,*=,/=.
Definition: xvector2.h:41
T & operator*=(const T &v)
Definition: xvector2.h:47
static void error_if(const std::string &s, bool arg)
error_if Fehler wenn Bedingung erfüllt ist
Definition: xerror.h:51
T & apply_fn(const X &v, FN fn)
apply_fn Hilfsfunktion
Definition: xvector2.h:26
T & operator-=(const T &v)
Definition: xvector2.h:44
#define nmx_msg
Definition: xerror.h:113
T & operator*=(double x)
Definition: xvector2.h:65
const gsl_vector * gsl() const
ermöglicht direkten Zugriff auf gsl-Funktionen
Definition: xvector0.h:18
T & operator/=(const T &v)
Definition: xvector2.h:50
T & operator/=(double x)
operator /= dividiere alle Elemente mit einer Zahl
Definition: xvector2.h:74
The IGslContainer struct Basisklasse für gsl-Vektoren und Matrizen.
Definition: xvector0.h:13
T & operator-=(double x)
Definition: xvector2.h:62