forked from mpusz/mp-units
fix: quantity's compound operators fixed to behave like int
s do
This commit is contained in:
@@ -203,15 +203,17 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr quantity& operator*=(const rep& rhs)
|
template<typename Rep2>
|
||||||
requires requires(rep a, const rep b) { { a *= b } -> std::same_as<rep&>; }
|
constexpr quantity& operator*=(const Rep2& rhs)
|
||||||
|
requires requires(rep a, const Rep2 b) { { a *= b } -> std::same_as<rep&>; }
|
||||||
{
|
{
|
||||||
value_ *= rhs;
|
value_ *= rhs;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr quantity& operator/=(const rep& rhs)
|
template<typename Rep2>
|
||||||
requires requires(rep a, const rep b) { { a /= b } -> std::same_as<rep&>; }
|
constexpr quantity& operator/=(const Rep2& rhs)
|
||||||
|
requires requires(rep a, const Rep2 b) { { a /= b } -> std::same_as<rep&>; }
|
||||||
{
|
{
|
||||||
value_ /= rhs;
|
value_ /= rhs;
|
||||||
return *this;
|
return *this;
|
||||||
|
@@ -51,3 +51,5 @@ target_link_libraries(unit_tests_static
|
|||||||
PRIVATE
|
PRIVATE
|
||||||
mp::units
|
mp::units
|
||||||
)
|
)
|
||||||
|
|
||||||
|
set_source_files_properties(quantity_test.cpp PROPERTIES COMPILE_FLAGS -Wno-conversion)
|
||||||
|
@@ -283,6 +283,11 @@ static_assert((2.5_q_m *= 3).count() == 7.5);
|
|||||||
static_assert((7.5_q_m /= 3).count() == 2.5);
|
static_assert((7.5_q_m /= 3).count() == 2.5);
|
||||||
static_assert((3500_q_m %= 1_q_km).count() == 500);
|
static_assert((3500_q_m %= 1_q_km).count() == 500);
|
||||||
|
|
||||||
|
// next two lines trigger the gcc 'Wconversion' warning
|
||||||
|
// (warning disabled in CMake for this file)
|
||||||
|
static_assert((22_q_m *= 33.33).count() == 733);
|
||||||
|
static_assert((22_q_m /= 3.33).count() == 6);
|
||||||
|
|
||||||
template<typename Metre>
|
template<typename Metre>
|
||||||
concept invalid_compound_assignments = requires() {
|
concept invalid_compound_assignments = requires() {
|
||||||
// truncating not allowed
|
// truncating not allowed
|
||||||
|
Reference in New Issue
Block a user