pow<0> support added

This commit is contained in:
Mateusz Pusz
2019-10-19 20:51:20 +02:00
parent b2f33c6dfa
commit 8543ab65d1
3 changed files with 9 additions and 1 deletions

View File

@@ -27,6 +27,13 @@
namespace units {
template<std::size_t N, typename U, typename Rep>
requires N == 0
inline Rep AUTO pow(const quantity<U, Rep>&) noexcept
{
return 1;
}
template<std::size_t N, typename U, typename Rep>
inline Quantity AUTO pow(const quantity<U, Rep>& q) noexcept
{

View File

@@ -31,7 +31,7 @@ using namespace units;
TEST_CASE("pow<N>() on quantity changes the value and the dimension accordingly", "[math][pow]")
{
// CHECK(pow<0>(2m) == 2);
CHECK(pow<0>(2m) == 1);
CHECK(pow<1>(2m) == 2m);
CHECK(pow<2>(2m) == 4sq_m);
CHECK(pow<3>(2m) == 8cub_m);

View File

@@ -27,6 +27,7 @@ using namespace units;
namespace {
static_assert(std::is_same_v<decltype(pow<0>(2m)), std::int64_t>);
static_assert(std::is_same_v<decltype(pow<1>(2m)), decltype(2m)>);
static_assert(std::is_same_v<decltype(pow<2>(2m)), decltype(4sq_m)>);
static_assert(std::is_same_v<decltype(sqrt(4sq_m)), decltype(2m)>);