diff --git a/modules/geom/src/vec2.hh b/modules/geom/src/vec2.hh index 391e073ff17909e411a3d7eb676a2d7d6026a774..8432856ead98214eccd77c9deeebeb9c064014f8 100644 --- a/modules/geom/src/vec2.hh +++ b/modules/geom/src/vec2.hh @@ -19,6 +19,7 @@ #ifndef GEOM_VEC2_H #define GEOM_VEC2_H +#include <stdexcept> #include <cstddef> // for size_t #include <ostream> #include <vector> @@ -82,13 +83,18 @@ public: //! element access Real& operator[](std::size_t indx) { + if (indx>1) { + throw std::out_of_range("Index must be in the range [0-1]"); + } return (&x)[indx]; } //! const element access const Real& operator[](std::size_t indx) const { - + if (indx>1) { + throw std::out_of_range("Index must be in the range [0-1]"); + } return (&x)[indx]; } diff --git a/modules/geom/src/vec3.hh b/modules/geom/src/vec3.hh index 627de4c1ee9cea9f6da151cd98a1a70879ab8c19..5283146a11840df78450a5ea960a00c374b35293 100644 --- a/modules/geom/src/vec3.hh +++ b/modules/geom/src/vec3.hh @@ -19,6 +19,7 @@ #ifndef GEOM_VEC3_H #define GEOM_VEC3_H +#include <stdexcept> #include <cstddef> // for size_t #include <ostream> #include <vector> @@ -88,13 +89,18 @@ public: //! element access Real& operator[](std::size_t indx) { + if (indx>2) { + throw std::out_of_range("Index must be in the range [0-2]"); + } return (&x)[indx]; } //! const element access const Real& operator[](std::size_t indx) const { - + if (indx>2) { + throw std::out_of_range("Index must be in the range [0-2]"); + } return (&x)[indx]; } //! element access diff --git a/modules/geom/src/vec4.hh b/modules/geom/src/vec4.hh index ad3367b97b8f7f30f95aab6c5da54ccc91cb987d..5442fc2037b6238a8e84858eb814159b9d7f52d3 100644 --- a/modules/geom/src/vec4.hh +++ b/modules/geom/src/vec4.hh @@ -19,6 +19,7 @@ #ifndef GEOM_VEC4_H #define GEOM_VEC4_H +#include <stdexcept> #include <cstddef> // for size_t #include <ostream> @@ -82,13 +83,18 @@ public: //! element access Real& operator[](std::size_t indx) { + if (indx>3) { + throw std::out_of_range("Index must be in the range [0-3]"); + } return (&x)[indx]; } //! const element access const Real& operator[](std::size_t indx) const { - + if (indx>3) { + throw std::out_of_range("Index must be in the range [0-3]"); + } return (&x)[indx]; } //! element access