Commit 3fb1241c authored by Jan Koniarik's avatar Jan Koniarik
Browse files

added fixes due to examples

parent d0e4b792
......@@ -61,4 +61,10 @@ class subscript_iterator : public generic_iterator<subscript_iterator<Container>
}
};
template <typename Container>
view<subscript_iterator<Container>> subscript_view(Container &cont) {
return view{subscript_iterator<Container>{cont, 0},
subscript_iterator<Container>{cont, cont.size()}};
}
} // namespace emlabcpp
......@@ -61,6 +61,7 @@ using amount_of_substance = physical_quantity<0, 0, 0, 0, 0, 1, 0, 0, 0>;
using luminous_intensity = physical_quantity<0, 0, 0, 0, 0, 0, 1, 0, 0>;
using angle = physical_quantity<0, 0, 0, 0, 0, 0, 0, 1, 0>;
using byte = physical_quantity<0, 0, 0, 0, 0, 0, 0, 0, 1>;
using acceleration = physical_quantity<1, 0, -2, 0, 0, 0, 0, 0, 0>;
using angular_velocity = physical_quantity<0, 0, -1, 0, 0, 0, 0, 1, 0>;
using area = physical_quantity<2, 0, 0, 0, 0, 0, 0, 0, 0>;
using volume = physical_quantity<3, 0, 0, 0, 0, 0, 0, 0, 0>;
......@@ -113,6 +114,17 @@ constexpr auto sqrt(physical_quantity<Len, Mass, Time, Current, Temp, Mol, Li, A
Li / 2, Angle / 2, Byte / 2>{float{std::sqrt(*val)}};
}
/// Power of physical quantity is power of root of it's value and the exponents are multiplied by
/// the value.
template <unsigned Power, int Len, int Mass, int Time, int Current, int Temp, int Mol, int Li,
int Angle, int Byte>
constexpr auto sqrt(physical_quantity<Len, Mass, Time, Current, Temp, Mol, Li, Angle, Byte> val) {
return physical_quantity<Len * Power, Mass * Power, Time * Power, Current * Power,
Temp * Power, Mol * Power, Li * Power, Angle * Power,
Byte * Power>{float{std::pow(*val, Power)}};
}
} // namespace emlabcpp
/// std::numeric_limits<physical_quantity> follows same logic as std::numeric_limits<float>;
......
......@@ -27,6 +27,7 @@ TEST(physical_quantity_test, basic) {
EXPECT_EQ(sin(unitless{0.f}), 0.);
EXPECT_EQ(max(unitless{0.5f}, unitless{1.f}), unitless{1.f});
EXPECT_EQ(min(unitless{0.5f}, unitless{1.f}), unitless{0.5f});
EXPECT_EQ(pow<2>(unitless{2.f}), unitless{4.f});
}
TEST(physical_quantity_test, specializations) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment