Skip to content
Snippets Groups Projects
Commit a104ae53 authored by marco's avatar marco
Browse files

readded boundary checks to Vec{2,3,4}::operator[]

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2572 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent 80ac28cf
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#ifndef GEOM_VEC2_H #ifndef GEOM_VEC2_H
#define GEOM_VEC2_H #define GEOM_VEC2_H
#include <stdexcept>
#include <cstddef> // for size_t #include <cstddef> // for size_t
#include <ostream> #include <ostream>
#include <vector> #include <vector>
...@@ -82,13 +83,18 @@ public: ...@@ -82,13 +83,18 @@ public:
//! element access //! element access
Real& operator[](std::size_t indx) 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]; return (&x)[indx];
} }
//! const element access //! const element access
const Real& operator[](std::size_t indx) const 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]; return (&x)[indx];
} }
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#ifndef GEOM_VEC3_H #ifndef GEOM_VEC3_H
#define GEOM_VEC3_H #define GEOM_VEC3_H
#include <stdexcept>
#include <cstddef> // for size_t #include <cstddef> // for size_t
#include <ostream> #include <ostream>
#include <vector> #include <vector>
...@@ -88,13 +89,18 @@ public: ...@@ -88,13 +89,18 @@ public:
//! element access //! element access
Real& operator[](std::size_t indx) 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]; return (&x)[indx];
} }
//! const element access //! const element access
const Real& operator[](std::size_t indx) const 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]; return (&x)[indx];
} }
//! element access //! element access
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#ifndef GEOM_VEC4_H #ifndef GEOM_VEC4_H
#define GEOM_VEC4_H #define GEOM_VEC4_H
#include <stdexcept>
#include <cstddef> // for size_t #include <cstddef> // for size_t
#include <ostream> #include <ostream>
...@@ -82,13 +83,18 @@ public: ...@@ -82,13 +83,18 @@ public:
//! element access //! element access
Real& operator[](std::size_t indx) 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]; return (&x)[indx];
} }
//! const element access //! const element access
const Real& operator[](std::size_t indx) const 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]; return (&x)[indx];
} }
//! element access //! element access
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment