mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-04 12:54:25 +02:00
refactor: more constraints added to floor
and ceil
This commit is contained in:
@@ -155,9 +155,13 @@ template<Quantity Q>
|
|||||||
*/
|
*/
|
||||||
template<Unit To, typename D, typename U, typename Rep>
|
template<Unit To, typename D, typename U, typename Rep>
|
||||||
[[nodiscard]] constexpr quantity<D, To, Rep> floor(const quantity<D, U, Rep>& q) noexcept
|
[[nodiscard]] constexpr quantity<D, To, Rep> floor(const quantity<D, U, Rep>& q) noexcept
|
||||||
requires (!treat_as_floating_point<Rep>) ||
|
requires ((!treat_as_floating_point<Rep>) ||
|
||||||
requires { floor(q.number()); } ||
|
requires { floor(q.number()); } ||
|
||||||
requires { std::floor(q.number()); }
|
requires { std::floor(q.number()); }) &&
|
||||||
|
(std::same_as<To, U> || requires {
|
||||||
|
::units::quantity_cast<To>(q);
|
||||||
|
quantity<D, To, Rep>::one();
|
||||||
|
})
|
||||||
{
|
{
|
||||||
const auto handle_signed_results = [&]<typename T>(const T& res) {
|
const auto handle_signed_results = [&]<typename T>(const T& res) {
|
||||||
if (res > q)
|
if (res > q)
|
||||||
@@ -191,9 +195,13 @@ template<Unit To, typename D, typename U, typename Rep>
|
|||||||
*/
|
*/
|
||||||
template<Unit To, typename D, typename U, typename Rep>
|
template<Unit To, typename D, typename U, typename Rep>
|
||||||
[[nodiscard]] constexpr quantity<D, To, Rep> ceil(const quantity<D, U, Rep>& q) noexcept
|
[[nodiscard]] constexpr quantity<D, To, Rep> ceil(const quantity<D, U, Rep>& q) noexcept
|
||||||
requires (!treat_as_floating_point<Rep>) ||
|
requires ((!treat_as_floating_point<Rep>) ||
|
||||||
requires { ceil(q.number()); } ||
|
requires { ceil(q.number()); } ||
|
||||||
requires { std::ceil(q.number()); }
|
requires { std::ceil(q.number()); }) &&
|
||||||
|
(std::same_as<To, U> || requires {
|
||||||
|
::units::quantity_cast<To>(q);
|
||||||
|
quantity<D, To, Rep>::one();
|
||||||
|
})
|
||||||
{
|
{
|
||||||
const auto handle_signed_results = [&]<typename T>(const T& res) {
|
const auto handle_signed_results = [&]<typename T>(const T& res) {
|
||||||
if (res < q)
|
if (res < q)
|
||||||
|
Reference in New Issue
Block a user