diff --git a/include/alpaka/vec/Vec.hpp b/include/alpaka/vec/Vec.hpp index d327f60ff45..b0e2dba5f10 100644 --- a/include/alpaka/vec/Vec.hpp +++ b/include/alpaka/vec/Vec.hpp @@ -368,6 +368,12 @@ namespace alpaka return (*this)[I]; } + //! \return The number of dimensions of the vector. + [[nodiscard]] ALPAKA_FN_HOST_ACC static consteval auto dim() noexcept -> TVal + { + return TDim::value; + } + //! \return The element-wise sum of two vectors. ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC friend constexpr auto operator+(Vec const& p, Vec const& q) -> Vec diff --git a/test/unit/vec/src/VecTest.cpp b/test/unit/vec/src/VecTest.cpp index d559b47a5d3..837d4acc27c 100644 --- a/test/unit/vec/src/VecTest.cpp +++ b/test/unit/vec/src/VecTest.cpp @@ -177,7 +177,14 @@ TEST_CASE("basicVecTraits", "[vec]") } { - constexpr alpaka::Vec vec3(static_cast(47u), static_cast(8u), static_cast(3u)); + using Vec3 = alpaka::Vec; + constexpr Vec3 vec3(static_cast(47u), static_cast(8u), static_cast(3u)); + + // alpaka::Vec::dim + { + STATIC_REQUIRE(vec3.dim() == 3); + STATIC_REQUIRE(Vec3::dim() == 3); + } // alpaka::Vec operator + {