Skip to content

Commit

Permalink
Kleinere Aufräumarbeiten
Browse files Browse the repository at this point in the history
  • Loading branch information
martinfehrs committed Jan 23, 2024
1 parent 380f96d commit 4b7fd8c
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 72 deletions.
2 changes: 1 addition & 1 deletion include/zollstock/angle_unit_constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace zollstock::inline unit::inline constants

ZOLLSTOCK_DEFINE_SI_BASE_UNIT_CONSTANTS(radian, rad)

inline constexpr degree deg {};
inline constexpr degree deg{};

inline constexpr arcminute arcmin{};

Expand Down
63 changes: 39 additions & 24 deletions include/zollstock/quantity_exponents.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,58 +16,73 @@ namespace zollstock
int angle;
};

template <std::size_t... indices>
[[nodiscard]] constexpr quantity_exponents add(
const quantity_exponents& exponents_1,
const quantity_exponents& exponents_2,
std::index_sequence<indices...>
) noexcept
namespace detail
{
return { (get<indices>(exponents_1) + get<indices>(exponents_2))... };

template <std::size_t... indices>
[[nodiscard]] constexpr quantity_exponents add(
const quantity_exponents& exponents_1,
const quantity_exponents& exponents_2,
std::index_sequence<indices...>
) noexcept
{
return { (get<indices>(exponents_1) + get<indices>(exponents_2))... };
}

}

[[nodiscard]] constexpr auto operator+(
const quantity_exponents& exponents_1,
const quantity_exponents& exponents_2
) noexcept
{
return add(exponents_1, exponents_2, make_quantity_index_sequence{});
return detail::add(exponents_1, exponents_2, make_quantity_index_sequence{});
}

template <std::size_t... indices>
[[nodiscard]] constexpr quantity_exponents sub(
const quantity_exponents& exponents_1,
const quantity_exponents& exponents_2,
std::index_sequence<indices...>
) noexcept
namespace detail
{
return { (get<indices>(exponents_1) - get<indices>(exponents_2))... };

template <std::size_t... indices>
[[nodiscard]] constexpr quantity_exponents sub(
const quantity_exponents& exponents_1,
const quantity_exponents& exponents_2,
std::index_sequence<indices...>
) noexcept
{
return { (get<indices>(exponents_1) - get<indices>(exponents_2))... };
}

}

[[nodiscard]] constexpr auto operator-(
const quantity_exponents& exponents_1,
const quantity_exponents& exponents_2
) noexcept
{
return sub(exponents_1, exponents_2, make_quantity_index_sequence{});
return detail::sub(exponents_1, exponents_2, make_quantity_index_sequence{});
}

template <std::size_t... indices>
[[nodiscard]] constexpr quantity_exponents mul(
const quantity_exponents& exponents,
int factor,
std::index_sequence<indices...>
) noexcept
namespace detail
{
return { (get<indices>(exponents) * factor)... };

template <std::size_t... indices>
[[nodiscard]] constexpr quantity_exponents mul(
const quantity_exponents& exponents,
int factor,
std::index_sequence<indices...>
) noexcept
{
return { (get<indices>(exponents) * factor)... };
}

}

[[nodiscard]] constexpr auto operator*(
const quantity_exponents& exponents,
int factor
) noexcept
{
return mul(exponents, factor, make_quantity_index_sequence{});
return detail::mul(exponents, factor, make_quantity_index_sequence{});
}
}

Expand Down
26 changes: 15 additions & 11 deletions include/zollstock/quantity_factors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,29 @@ namespace zollstock
long double angle;
};


template<std::size_t... indices>
[[nodiscard]] constexpr quantity_factors combined_impl(
const quantity_factors& factors_1,
const quantity_factors& factors_2,
std::index_sequence<indices...>
) noexcept
namespace detail
{
return {
((get<indices>(factors_1) != 0) ? get<indices>(factors_1) : get<indices>(factors_2))...
};

template<std::size_t... indices>
[[nodiscard]] constexpr quantity_factors combined_impl(
const quantity_factors& factors_1,
const quantity_factors& factors_2,
std::index_sequence<indices...>
) noexcept
{
return {
((get<indices>(factors_1) != 0) ? get<indices>(factors_1) : get<indices>(factors_2))...
};
}

}

[[nodiscard]] constexpr quantity_factors combined(
const quantity_factors& factors_1,
const quantity_factors& factors_2
) noexcept
{
return combined_impl(
return detail::combined_impl(
factors_1,
factors_2,
make_quantity_index_sequence{}
Expand Down
78 changes: 43 additions & 35 deletions include/zollstock/quantity_symbols.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,50 +15,58 @@ namespace zollstock
{
unit_symbol length;
unit_symbol time;

unit_symbol angle;
};

template <std::size_t pos>
[[nodiscard]] constexpr unit_symbol select_symbol_entry(
const quantity_exponents& exponents,
const quantity_symbols& symbols_1,
const quantity_symbols& symbols_2
)
namespace detail
{
const unit_symbol& symbol_1 = get<pos>(symbols_1);
const unit_symbol& symbol_2 = get<pos>(symbols_2);

if (get<pos>(exponents) == 0)
template <std::size_t pos>
[[nodiscard]] constexpr unit_symbol select_symbol_entry(
const quantity_exponents& exponents,
const quantity_symbols& symbols_1,
const quantity_symbols& symbols_2
)
{
return ""_us;
}
else if (symbol_1.size() == 0)
{
return symbol_2;
}
else if (symbol_2.size() == 0)
{
return symbol_1;
}
else if (symbol_1 == symbol_2)
{
return symbol_1;
const unit_symbol& symbol_1 = get<pos>(symbols_1);
const unit_symbol& symbol_2 = get<pos>(symbols_2);

if (get<pos>(exponents) == 0)
{
return ""_us;
}
else if (symbol_1.size() == 0)
{
return symbol_2;
}
else if (symbol_2.size() == 0)
{
return symbol_1;
}
else if (symbol_1 == symbol_2)
{
return symbol_1;
}
else
{
throw "incompatible symbols";
}
}
else

template<std::size_t... indices>
[[nodiscard]] constexpr auto select_symbols_impl(
const quantity_exponents& exponents,
const quantity_symbols& symbols_1,
const quantity_symbols& symbols_2,
std::index_sequence<indices...>
) noexcept
{
throw "incompatible symbols";
return quantity_symbols{
select_symbol_entry<indices>(exponents, symbols_1, symbols_2)...
};
}
}

template<std::size_t... indices>
[[nodiscard]] constexpr auto select_symbols(
const quantity_exponents& exponents,
const quantity_symbols& symbols_1,
const quantity_symbols& symbols_2,
std::index_sequence<indices...>
) noexcept
{
return quantity_symbols{ select_symbol_entry<indices>(exponents, symbols_1, symbols_2)... };
}

[[nodiscard]] constexpr inline auto select_symbols(
Expand All @@ -67,7 +75,7 @@ namespace zollstock
const quantity_symbols& symbols_2
) noexcept
{
return select_symbols(
return detail::select_symbols_impl(
exponents,
symbols_1,
symbols_2,
Expand Down
1 change: 0 additions & 1 deletion include/zollstock/scalar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ namespace zollstock
return scalar<Unit{}>{ factor };
}


template <unit_c auto unit>
[[nodiscard]] constexpr auto operator*(double factor_1, scalar<unit> factor_2) noexcept
{
Expand Down

0 comments on commit 4b7fd8c

Please sign in to comment.