Skip to content

Commit 7b3dc0f

Browse files
committed
constexpr
1 parent da39f6d commit 7b3dc0f

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

src/r4/vector.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ class vector :
674674
* @param num - scalar to multiply by.
675675
* @return Reference to this vector object.
676676
*/
677-
vector& operator*=(component_type num) noexcept
677+
constexpr vector& operator*=(component_type num) noexcept
678678
{
679679
return this->comp_operation([&num](auto& a) {
680680
return a * num;
@@ -687,7 +687,7 @@ class vector :
687687
* @param num - scalar to multiply by.
688688
* @return Vector resulting from multiplication of this vector by scalar.
689689
*/
690-
vector operator*(component_type num) const noexcept
690+
constexpr vector operator*(component_type num) const noexcept
691691
{
692692
return (vector(*this) *= num);
693693
}

tests/unit/src/vector4.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,5 +534,21 @@ const tst::set set("vector4", [](tst::suite& suite){
534534
tst::check_eq(r[2], -4, SL);
535535
tst::check_eq(r[3], -6, SL);
536536
});
537+
538+
suite.add("constexprness", [](){
539+
// operator/(number)
540+
{
541+
constexpr auto v = r4::vector4<unsigned>(10, 20, 30, 40) / 2;
542+
tst::check_eq(v, r4::vector4<unsigned>(10, 20, 30, 40) / 2, SL);
543+
}
544+
545+
// operator*(number)
546+
{
547+
constexpr auto v = r4::vector4<unsigned>(10, 20, 30, 40) * 2;
548+
tst::check_eq(v, r4::vector4<unsigned>(10, 20, 30, 40) * 2, SL);
549+
}
550+
551+
// TODO: add other operators and functions
552+
});
537553
});
538554
}

0 commit comments

Comments
 (0)