diff --git a/libs/geom/include/psemek/geom/box.hpp b/libs/geom/include/psemek/geom/box.hpp index 6496775e..3c04077f 100644 --- a/libs/geom/include/psemek/geom/box.hpp +++ b/libs/geom/include/psemek/geom/box.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -9,7 +10,7 @@ namespace psemek::geom template struct box { - interval axes[N]; + detail::array, N>::type axes; using point_type = point; using vector_type = vector; diff --git a/libs/geom/include/psemek/geom/detail/array.hpp b/libs/geom/include/psemek/geom/detail/array.hpp new file mode 100644 index 00000000..0fb73944 --- /dev/null +++ b/libs/geom/include/psemek/geom/detail/array.hpp @@ -0,0 +1,33 @@ +#pragma once + +#include + +namespace psemek::geom::detail +{ + + struct empty_array_exception + : std::exception + { + char const * what() const noexcept + { + return "Attempt to index a zero vector"; + } + }; + + template + struct array + { + using type = T[N]; + }; + + template + struct array + { + struct type + { + T const & operator[](std::size_t) const { throw empty_array_exception{}; } + T & operator[](std::size_t) { throw empty_array_exception{}; } + }; + }; + +} diff --git a/libs/geom/include/psemek/geom/matrix.hpp b/libs/geom/include/psemek/geom/matrix.hpp index dd35a9de..3f8d7059 100644 --- a/libs/geom/include/psemek/geom/matrix.hpp +++ b/libs/geom/include/psemek/geom/matrix.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -15,7 +16,7 @@ namespace psemek::geom using scalar_type = T; - T coords[R * C]; + detail::array::type coords; T * operator[](std::size_t i) { diff --git a/libs/geom/include/psemek/geom/point.hpp b/libs/geom/include/psemek/geom/point.hpp index 040ad9f8..51dff048 100644 --- a/libs/geom/include/psemek/geom/point.hpp +++ b/libs/geom/include/psemek/geom/point.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include namespace psemek::geom @@ -12,7 +13,7 @@ namespace psemek::geom using scalar_type = T; - T coords[N]; + detail::array::type coords; point() = default; point(point const &) = default; diff --git a/libs/geom/include/psemek/geom/vector.hpp b/libs/geom/include/psemek/geom/vector.hpp index f4947f5d..b44aec6c 100644 --- a/libs/geom/include/psemek/geom/vector.hpp +++ b/libs/geom/include/psemek/geom/vector.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #include #include #include @@ -9,27 +11,6 @@ namespace psemek::geom { - namespace detail - { - - template - struct empty_array_helper - { - using type = T[N]; - }; - - template - struct empty_array_helper - { - struct type - { - T const & operator[](std::size_t) const { throw std::runtime_error("Attempt to index a zero vector"); } - T & operator[](std::size_t) { throw std::runtime_error("Attempt to index a zero vector"); } - }; - }; - - } - template struct vector { @@ -37,7 +18,7 @@ namespace psemek::geom using scalar_type = T; - detail::empty_array_helper::type coords; + detail::array::type coords; vector() = default; vector(vector const &) = default;