mirror of
https://github.com/BlackMATov/vmath.hpp.git
synced 2025-12-15 12:39:47 +07:00
data function for vector and matrix
This commit is contained in:
@@ -134,6 +134,9 @@ public:
|
|||||||
|
|
||||||
void swap(vec& other) noexcept(is_nothrow_swappable_v<T>);
|
void swap(vec& other) noexcept(is_nothrow_swappable_v<T>);
|
||||||
|
|
||||||
|
constexpr pointer data() noexcept;
|
||||||
|
constexpr const_pointer data() const noexcept;
|
||||||
|
|
||||||
constexpr reference at(size_t index);
|
constexpr reference at(size_t index);
|
||||||
constexpr const_reference at(size_t index) const;
|
constexpr const_reference at(size_t index) const;
|
||||||
|
|
||||||
@@ -275,6 +278,9 @@ public:
|
|||||||
|
|
||||||
void swap(mat& other) noexcept(is_nothrow_swappable_v<T>);
|
void swap(mat& other) noexcept(is_nothrow_swappable_v<T>);
|
||||||
|
|
||||||
|
constexpr pointer data() noexcept;
|
||||||
|
constexpr const_pointer data() const noexcept;
|
||||||
|
|
||||||
constexpr reference at(size_t index);
|
constexpr reference at(size_t index);
|
||||||
constexpr const_reference at(size_t index) const;
|
constexpr const_reference at(size_t index) const;
|
||||||
|
|
||||||
|
|||||||
@@ -204,10 +204,18 @@ namespace vmath_hpp
|
|||||||
void swap(mat& other) noexcept(std::is_nothrow_swappable_v<T>) {
|
void swap(mat& other) noexcept(std::is_nothrow_swappable_v<T>) {
|
||||||
for ( std::size_t i = 0; i < Size; ++i ) {
|
for ( std::size_t i = 0; i < Size; ++i ) {
|
||||||
using std::swap;
|
using std::swap;
|
||||||
swap((*this)[i], other[i]);
|
swap(rows[i], other.rows[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr pointer data() noexcept {
|
||||||
|
return &rows[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr const_pointer data() const noexcept {
|
||||||
|
return &rows[0];
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr reference operator[](std::size_t index) noexcept {
|
[[nodiscard]] constexpr reference operator[](std::size_t index) noexcept {
|
||||||
return rows[index];
|
return rows[index];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -175,6 +175,14 @@ namespace vmath_hpp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr pointer data() noexcept {
|
||||||
|
return &(*this)[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr const_pointer data() const noexcept {
|
||||||
|
return &(*this)[0];
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr reference at(std::size_t index) {
|
[[nodiscard]] constexpr reference at(std::size_t index) {
|
||||||
if ( index >= Size ) {
|
if ( index >= Size ) {
|
||||||
throw std::out_of_range("vec::at");
|
throw std::out_of_range("vec::at");
|
||||||
|
|||||||
@@ -121,6 +121,29 @@ TEST_CASE("vmath/mat") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SUBCASE("data") {
|
||||||
|
{
|
||||||
|
int2x2 m2;
|
||||||
|
STATIC_REQUIRE(m2.data() == &m2[0]);
|
||||||
|
|
||||||
|
int3x3 m3;
|
||||||
|
STATIC_REQUIRE(m3.data() == &m3[0]);
|
||||||
|
|
||||||
|
int4x4 m4;
|
||||||
|
STATIC_REQUIRE(m4.data() == &m4[0]);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
constexpr int2x2 m2;
|
||||||
|
STATIC_REQUIRE(m2.data() == &m2[0]);
|
||||||
|
|
||||||
|
constexpr int3x3 m3;
|
||||||
|
STATIC_REQUIRE(m3.data() == &m3[0]);
|
||||||
|
|
||||||
|
constexpr int4x4 m4;
|
||||||
|
STATIC_REQUIRE(m4.data() == &m4[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SUBCASE("operator[]") {
|
SUBCASE("operator[]") {
|
||||||
{
|
{
|
||||||
STATIC_REQUIRE(int2x2()[0] == int2(1,0));
|
STATIC_REQUIRE(int2x2()[0] == int2(1,0));
|
||||||
|
|||||||
@@ -118,6 +118,29 @@ TEST_CASE("vmath/vec") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SUBCASE("data") {
|
||||||
|
{
|
||||||
|
int2 i2;
|
||||||
|
REQUIRE(i2.data() == &i2[0]);
|
||||||
|
|
||||||
|
int3 i3;
|
||||||
|
REQUIRE(i3.data() == &i3[0]);
|
||||||
|
|
||||||
|
int4 i4;
|
||||||
|
REQUIRE(i4.data() == &i4[0]);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
constexpr int2 i2;
|
||||||
|
STATIC_REQUIRE(i2.data() == &i2[0]);
|
||||||
|
|
||||||
|
constexpr int3 i3;
|
||||||
|
STATIC_REQUIRE(i3.data() == &i3[0]);
|
||||||
|
|
||||||
|
constexpr int4 i4;
|
||||||
|
STATIC_REQUIRE(i4.data() == &i4[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SUBCASE("operator[]") {
|
SUBCASE("operator[]") {
|
||||||
{
|
{
|
||||||
STATIC_REQUIRE(int2(1,2).x == 1);
|
STATIC_REQUIRE(int2(1,2).x == 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user