style: all files refromatted with clang-format
This commit is contained in:
1 parent
cc90985958
commit
144f6951c0
143 files changed
+5845
-3563
No files matched your search
@@ -100,4 +100,4 @@ static_assert(10_q_erg / 1_q_erg_per_s == 10_q_s);
|
||||
|
||||
static_assert(detail::unit_text<dim_power, erg_per_second>() == "erg/s");
|
||||
|
||||
}
|
||||
} // namespace
|
||||
@@ -34,9 +34,11 @@ using namespace units::isq;
|
||||
using namespace units::isq::si::literals;
|
||||
using namespace std::chrono_literals;
|
||||
using sys_seconds = std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds>;
|
||||
using sys_days = std::chrono::time_point<std::chrono::system_clock,
|
||||
std::chrono::duration<long, std::ratio_multiply<std::ratio<24>, std::chrono::hours::period>>>;
|
||||
template<typename C, typename U, typename Rep = double> using time_point = quantity_point<clock_origin<C>, U, Rep>;
|
||||
using sys_days =
|
||||
std::chrono::time_point<std::chrono::system_clock,
|
||||
std::chrono::duration<long, std::ratio_multiply<std::ratio<24>, std::chrono::hours::period>>>;
|
||||
template<typename C, typename U, typename Rep = double>
|
||||
using time_point = quantity_point<clock_origin<C>, U, Rep>;
|
||||
|
||||
static_assert(QuantityLike<std::chrono::seconds>);
|
||||
static_assert(QuantityPointLike<sys_seconds>);
|
||||
@@ -50,8 +52,10 @@ static_assert(std::constructible_from<si::time<si::second, std::chrono::hours::r
|
||||
static_assert(!std::convertible_to<std::chrono::hours, si::time<si::second, std::chrono::hours::rep>>);
|
||||
static_assert(!std::constructible_from<si::time<si::hour, std::chrono::seconds::rep>, std::chrono::seconds>);
|
||||
static_assert(!std::convertible_to<std::chrono::seconds, si::time<si::hour, std::chrono::seconds::rep>>);
|
||||
static_assert(std::constructible_from<time_point<std::chrono::system_clock, si::second, sys_seconds::rep>, sys_seconds>);
|
||||
static_assert(!std::constructible_from<time_point<std::chrono::steady_clock, si::second, sys_seconds::rep>, sys_seconds>);
|
||||
static_assert(
|
||||
std::constructible_from<time_point<std::chrono::system_clock, si::second, sys_seconds::rep>, sys_seconds>);
|
||||
static_assert(
|
||||
!std::constructible_from<time_point<std::chrono::steady_clock, si::second, sys_seconds::rep>, sys_seconds>);
|
||||
static_assert(!std::convertible_to<sys_seconds, time_point<std::chrono::system_clock, si::second, sys_seconds::rep>>);
|
||||
static_assert(std::constructible_from<time_point<std::chrono::system_clock, si::day, sys_days::rep>, sys_days>);
|
||||
static_assert(!std::constructible_from<time_point<std::chrono::steady_clock, si::day, sys_days::rep>, sys_days>);
|
||||
@@ -80,8 +84,10 @@ static_assert(!std::convertible_to<sys_seconds, time_point<std::chrono::system_c
|
||||
// CTAD
|
||||
static_assert(is_same_v<decltype(quantity{1s}), si::time<si::second, std::chrono::seconds::rep>>);
|
||||
static_assert(is_same_v<decltype(quantity{1h}), si::time<si::hour, std::chrono::hours::rep>>);
|
||||
static_assert(is_same_v<decltype(quantity_point{sys_seconds{1s}}), time_point<std::chrono::system_clock, si::second, sys_seconds::rep>>);
|
||||
static_assert(is_same_v<decltype(quantity_point{sys_days{sys_days::duration{1}}}), time_point<std::chrono::system_clock, si::day, sys_days::rep>>);
|
||||
static_assert(is_same_v<decltype(quantity_point{sys_seconds{1s}}),
|
||||
time_point<std::chrono::system_clock, si::second, sys_seconds::rep>>);
|
||||
static_assert(is_same_v<decltype(quantity_point{sys_days{sys_days::duration{1}}}),
|
||||
time_point<std::chrono::system_clock, si::day, sys_days::rep>>);
|
||||
|
||||
// operators
|
||||
static_assert(quantity{1s} + 1_q_s == 2_q_s);
|
||||
|
||||
@@ -20,15 +20,15 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/chrono.h>
|
||||
#include <units/isq/si/cgs/length.h>
|
||||
#include <units/isq/si/cgs/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/cgs/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/fps/length.h>
|
||||
#include <units/isq/si/fps/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/length.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/fps/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/length.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/prefixes.h>
|
||||
#include <units/isq/si/speed.h>
|
||||
#include <units/quantity_point_kind.h>
|
||||
#include <units/chrono.h>
|
||||
#include <chrono>
|
||||
#include <complex>
|
||||
#include <mutex>
|
||||
@@ -141,9 +141,13 @@ static_assert(QuantityOf<si::cgs::length<si::metre>, si::dim_length>);
|
||||
static_assert(QuantityOf<si::cgs::length<si::cgs::centimetre>, si::fps::dim_length>);
|
||||
static_assert(!QuantityOf<si::cgs::length<si::cgs::centimetre>, si::dim_time>);
|
||||
|
||||
static_assert(QuantityPointOf<quantity_point<dynamic_origin<si::dim_time>, si::second, int>, dynamic_origin<si::dim_time>>);
|
||||
static_assert(QuantityPointOf<quantity_point<clock_origin<std::chrono::system_clock>, si::second, int>, clock_origin<std::chrono::system_clock>>);
|
||||
static_assert(!QuantityPointOf<quantity_point<dynamic_origin<si::dim_time>, si::second, int>, clock_origin<std::chrono::system_clock>>);
|
||||
static_assert(!QuantityPointOf<quantity_point<clock_origin<std::chrono::system_clock>, si::second, int>, dynamic_origin<si::dim_time>>);
|
||||
static_assert(
|
||||
QuantityPointOf<quantity_point<dynamic_origin<si::dim_time>, si::second, int>, dynamic_origin<si::dim_time>>);
|
||||
static_assert(QuantityPointOf<quantity_point<clock_origin<std::chrono::system_clock>, si::second, int>,
|
||||
clock_origin<std::chrono::system_clock>>);
|
||||
static_assert(!QuantityPointOf<quantity_point<dynamic_origin<si::dim_time>, si::second, int>,
|
||||
clock_origin<std::chrono::system_clock>>);
|
||||
static_assert(!QuantityPointOf<quantity_point<clock_origin<std::chrono::system_clock>, si::second, int>,
|
||||
dynamic_origin<si::dim_time>>);
|
||||
|
||||
} // namespace
|
||||
@@ -30,13 +30,13 @@ namespace {
|
||||
|
||||
/**
|
||||
* @brief Representation type meeting minimum requirements
|
||||
*
|
||||
*
|
||||
* This type with a default Mode = 0 provides the minimum set of requirements to
|
||||
* satisfy @c Representation concept which is used for quantity's representation type.
|
||||
*
|
||||
*
|
||||
* In case of Mode != 0 only one of mandatory operation is removed which should
|
||||
* result in @c Representation concept not being satisfied.
|
||||
*
|
||||
*
|
||||
* @tparam Mode a flag to disable specific type's operations
|
||||
*/
|
||||
template<int Mode = 0>
|
||||
@@ -44,38 +44,64 @@ class min_expl {
|
||||
std::intmax_t value_;
|
||||
public:
|
||||
// default construction
|
||||
min_expl() requires (Mode != 1) = default;
|
||||
min_expl()
|
||||
requires(Mode != 1)
|
||||
= default;
|
||||
|
||||
// construction from std::int64_t
|
||||
constexpr explicit min_expl(std::intmax_t v) noexcept requires (Mode != 2) : value_(v) {}
|
||||
constexpr explicit min_expl(std::intmax_t v) noexcept
|
||||
requires(Mode != 2)
|
||||
: value_(v)
|
||||
{
|
||||
}
|
||||
|
||||
// copy construction
|
||||
min_expl(const min_expl&) requires (Mode != 3) = default;
|
||||
min_expl(const min_expl&)
|
||||
requires(Mode != 3)
|
||||
= default;
|
||||
|
||||
// move construction
|
||||
min_expl(min_expl&&) requires (Mode != 4) = default;
|
||||
min_expl(min_expl&&) requires (Mode == 4) = delete;
|
||||
min_expl(min_expl&&)
|
||||
requires(Mode != 4)
|
||||
= default;
|
||||
min_expl(min_expl&&)
|
||||
requires(Mode == 4)
|
||||
= delete;
|
||||
|
||||
// copy assignment
|
||||
min_expl& operator=(const min_expl&) requires (Mode != 5) = default;
|
||||
min_expl& operator=(const min_expl&)
|
||||
requires(Mode != 5)
|
||||
= default;
|
||||
|
||||
// move assignment
|
||||
min_expl& operator=(min_expl&&) requires (Mode != 6) = default;
|
||||
min_expl& operator=(min_expl&&) requires (Mode == 6) = delete;
|
||||
min_expl& operator=(min_expl&&)
|
||||
requires(Mode != 6)
|
||||
= default;
|
||||
min_expl& operator=(min_expl&&)
|
||||
requires(Mode == 6)
|
||||
= delete;
|
||||
|
||||
// equality
|
||||
[[nodiscard]] bool operator==(const min_expl&) const requires (Mode != 7) = default;
|
||||
[[nodiscard]] bool operator==(const min_expl&) const
|
||||
requires(Mode != 7)
|
||||
= default;
|
||||
|
||||
// scalability - multiplication
|
||||
[[nodiscard]] friend constexpr min_expl operator*(const min_expl& lhs, const min_expl& rhs) requires (Mode != 8)
|
||||
{ return min_expl(lhs.value_ * rhs.value_); }
|
||||
[[nodiscard]] friend constexpr min_expl operator*(const min_expl& lhs, const min_expl& rhs)
|
||||
requires(Mode != 8)
|
||||
{
|
||||
return min_expl(lhs.value_ * rhs.value_);
|
||||
}
|
||||
|
||||
// scalability - division
|
||||
[[nodiscard]] friend constexpr min_expl operator/(const min_expl& lhs, const min_expl& rhs) requires (Mode != 9)
|
||||
{ return min_expl(lhs.value_ / rhs.value_); }
|
||||
[[nodiscard]] friend constexpr min_expl operator/(const min_expl& lhs, const min_expl& rhs)
|
||||
requires(Mode != 9)
|
||||
{
|
||||
return min_expl(lhs.value_ / rhs.value_);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
||||
template<int Mode>
|
||||
struct std::common_type<std::intmax_t, min_expl<Mode>> : std::type_identity<min_expl<Mode>> {};
|
||||
@@ -161,53 +187,57 @@ static_assert(!Representation<min_expl<9>>);
|
||||
// quantity's operators should mirror the representation type capabilities
|
||||
template<typename Rep>
|
||||
concept invalid_member_operations = requires(length<metre, Rep> lhs) {
|
||||
requires !requires { +lhs; };
|
||||
requires !requires { -lhs; };
|
||||
requires !requires { ++lhs; };
|
||||
requires !requires { lhs++; };
|
||||
requires !requires { --lhs; };
|
||||
requires !requires { lhs--; };
|
||||
requires !requires { +lhs; };
|
||||
requires !requires { -lhs; };
|
||||
requires !requires { ++lhs; };
|
||||
requires !requires { lhs++; };
|
||||
requires !requires { --lhs; };
|
||||
requires !requires { lhs--; };
|
||||
|
||||
requires !requires(length<metre, Rep> rhs) { lhs += rhs; };
|
||||
requires !requires(length<metre, Rep> rhs) { lhs -= rhs; };
|
||||
requires !requires(Rep rhs) { lhs *= rhs; };
|
||||
requires !requires(Rep rhs) { lhs /= rhs; };
|
||||
requires !requires(Rep rhs) { lhs %= rhs; };
|
||||
requires !requires(length<metre, Rep> rhs) { lhs %= rhs; };
|
||||
requires !requires(length<metre, Rep> rhs) { lhs += rhs; };
|
||||
requires !requires(length<metre, Rep> rhs) { lhs -= rhs; };
|
||||
requires !requires(Rep rhs) { lhs *= rhs; };
|
||||
requires !requires(Rep rhs) { lhs /= rhs; };
|
||||
requires !requires(Rep rhs) { lhs %= rhs; };
|
||||
requires !requires(length<metre, Rep> rhs) { lhs %= rhs; };
|
||||
|
||||
requires !requires(length<metre, Rep> rhs) { lhs + rhs; };
|
||||
requires !requires(length<metre, Rep> rhs) { lhs - rhs; };
|
||||
requires !requires(Rep rhs) { lhs % rhs; };
|
||||
requires !requires(length<metre, Rep> rhs) { lhs % rhs; };
|
||||
requires !requires(length<metre, Rep> rhs) { lhs < rhs; };
|
||||
requires !requires(length<metre, Rep> rhs) { lhs > rhs; };
|
||||
requires !requires(length<metre, Rep> rhs) { lhs <= rhs; };
|
||||
requires !requires(length<metre, Rep> rhs) { lhs >= rhs; };
|
||||
requires !requires(length<metre, Rep> rhs) { lhs + rhs; };
|
||||
requires !requires(length<metre, Rep> rhs) { lhs - rhs; };
|
||||
requires !requires(Rep rhs) { lhs % rhs; };
|
||||
requires !requires(length<metre, Rep> rhs) { lhs % rhs; };
|
||||
requires !requires(length<metre, Rep> rhs) { lhs < rhs; };
|
||||
requires !requires(length<metre, Rep> rhs) { lhs > rhs; };
|
||||
requires !requires(length<metre, Rep> rhs) { lhs <= rhs; };
|
||||
requires !requires(length<metre, Rep> rhs) { lhs >= rhs; };
|
||||
|
||||
requires !requires(length<metre, int> rhs) { lhs + rhs; };
|
||||
requires !requires(length<metre, int> rhs) { lhs - rhs; };
|
||||
requires !requires(int rhs) { lhs % rhs; };
|
||||
requires !requires(length<metre, int> rhs) { lhs % rhs; };
|
||||
requires !requires(length<metre, int> rhs) { lhs == rhs; };
|
||||
requires !requires(length<metre, int> rhs) { lhs != rhs; };
|
||||
requires !requires(length<metre, int> rhs) { lhs < rhs; };
|
||||
requires !requires(length<metre, int> rhs) { lhs > rhs; };
|
||||
requires !requires(length<metre, int> rhs) { lhs <= rhs; };
|
||||
requires !requires(length<metre, int> rhs) { lhs >= rhs; };
|
||||
requires !requires(length<metre, int> rhs) { lhs + rhs; };
|
||||
requires !requires(length<metre, int> rhs) { lhs - rhs; };
|
||||
requires !requires(int rhs) { lhs % rhs; };
|
||||
requires !requires(length<metre, int> rhs) { lhs % rhs; };
|
||||
requires !requires(length<metre, int> rhs) { lhs == rhs; };
|
||||
requires !requires(length<metre, int> rhs) { lhs != rhs; };
|
||||
requires !requires(length<metre, int> rhs) { lhs < rhs; };
|
||||
requires !requires(length<metre, int> rhs) { lhs > rhs; };
|
||||
requires !requires(length<metre, int> rhs) { lhs <= rhs; };
|
||||
requires !requires(length<metre, int> rhs) { lhs >= rhs; };
|
||||
|
||||
requires !requires(std::ostream os) { os << lhs; };
|
||||
};
|
||||
requires !requires(std::ostream os) { os << lhs; };
|
||||
};
|
||||
static_assert(invalid_member_operations<min_expl<>>);
|
||||
|
||||
// equality
|
||||
static_assert(length<kilometre, min_expl<>>(min_expl(2)) == length<metre, min_expl<>>(min_expl(2000)));
|
||||
static_assert(length<metre, min_expl<>>(min_expl(123)) * min_expl(2) == length<metre, min_expl<>>(min_expl(246)));
|
||||
static_assert(length<metre, min_expl<>>(min_expl(123)) * quantity{min_expl(2)} == length<metre, min_expl<>>(min_expl(246)));
|
||||
static_assert(length<metre, min_expl<>>(min_expl(123)) * quantity{min_expl(2)} ==
|
||||
length<metre, min_expl<>>(min_expl(246)));
|
||||
static_assert(min_expl(2) * length<metre, min_expl<>>(min_expl(123)) == length<metre, min_expl<>>(min_expl(246)));
|
||||
static_assert(quantity{min_expl(2)} * length<metre, min_expl<>>(min_expl(123)) == length<metre, min_expl<>>(min_expl(246)));
|
||||
static_assert(quantity{min_expl(2)} * length<metre, min_expl<>>(min_expl(123)) ==
|
||||
length<metre, min_expl<>>(min_expl(246)));
|
||||
static_assert(length<metre, min_expl<>>(min_expl(246)) / min_expl(2) == length<metre, min_expl<>>(min_expl(123)));
|
||||
static_assert(length<metre, min_expl<>>(min_expl(246)) / quantity{min_expl(2)} == length<metre, min_expl<>>(min_expl(123)));
|
||||
static_assert(length<metre, min_expl<>>(min_expl(246)) / length<metre, min_expl<>>(min_expl(2)) == quantity{min_expl(123)});
|
||||
static_assert(length<metre, min_expl<>>(min_expl(246)) / quantity{min_expl(2)} ==
|
||||
length<metre, min_expl<>>(min_expl(123)));
|
||||
static_assert(length<metre, min_expl<>>(min_expl(246)) / length<metre, min_expl<>>(min_expl(2)) ==
|
||||
quantity{min_expl(123)});
|
||||
static_assert(length<metre, min_expl<>>(min_expl(246)) / length<metre, min_expl<>>(min_expl(2)) == min_expl(123));
|
||||
|
||||
} // namespace
|
||||
@@ -28,9 +28,9 @@ namespace {
|
||||
|
||||
/**
|
||||
* @brief Implicitly constructible and convertible representation type
|
||||
*
|
||||
*
|
||||
* A wrapper type that is implicitly convertible from and to the contained type.
|
||||
*
|
||||
*
|
||||
* @tparam T element type
|
||||
*/
|
||||
template<typename T>
|
||||
@@ -42,11 +42,13 @@ public:
|
||||
min_impl() = default;
|
||||
constexpr min_impl(T v) noexcept : value_(v) {}
|
||||
template<typename U>
|
||||
constexpr min_impl(min_impl<U> i) noexcept : value_(static_cast<T>(i.value_)) {}
|
||||
constexpr min_impl(min_impl<U> i) noexcept : value_(static_cast<T>(i.value_))
|
||||
{
|
||||
}
|
||||
constexpr operator T() const noexcept { return value_; }
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
||||
template<typename T, typename U>
|
||||
struct std::common_type<min_impl<T>, min_impl<U>> : std::common_type<T, U> {};
|
||||
@@ -125,7 +127,8 @@ static_assert(!std::convertible_to<min_impl<double>, dimensionless<percent, min_
|
||||
static_assert(std::constructible_from<dimensionless<percent, min_impl<double>>, min_impl<int>>);
|
||||
static_assert(!std::convertible_to<min_impl<int>, dimensionless<percent, min_impl<double>>>);
|
||||
|
||||
static_assert(!std::constructible_from<dimensionless<percent, min_impl<int>>, min_impl<double>>); // narrowing conversion
|
||||
static_assert(
|
||||
!std::constructible_from<dimensionless<percent, min_impl<int>>, min_impl<double>>); // narrowing conversion
|
||||
static_assert(!std::convertible_to<min_impl<double>, dimensionless<percent, min_impl<int>>>);
|
||||
|
||||
// implicit conversion tests
|
||||
@@ -191,7 +194,8 @@ static_assert(std::convertible_to<length<metre, min_impl<double>>, length<metre,
|
||||
static_assert(std::constructible_from<length<metre, min_impl<double>>, length<metre, min_impl<int>>>);
|
||||
static_assert(std::convertible_to<length<metre, min_impl<int>>, length<metre, min_impl<double>>>);
|
||||
|
||||
static_assert(!std::constructible_from<length<metre, min_impl<int>>, length<metre, min_impl<double>>>); // narrowing conversion
|
||||
static_assert(
|
||||
!std::constructible_from<length<metre, min_impl<int>>, length<metre, min_impl<double>>>); // narrowing conversion
|
||||
static_assert(!std::convertible_to<length<metre, min_impl<double>>, length<metre, min_impl<int>>>);
|
||||
|
||||
// T -> min_impl<T>
|
||||
@@ -204,7 +208,7 @@ static_assert(std::convertible_to<length<metre, double>, length<metre, min_impl<
|
||||
static_assert(std::constructible_from<length<metre, min_impl<double>>, length<metre, int>>);
|
||||
static_assert(std::convertible_to<length<metre, int>, length<metre, min_impl<double>>>);
|
||||
|
||||
static_assert(!std::constructible_from<length<metre, min_impl<int>>, length<metre, double>>); // narrowing conversion
|
||||
static_assert(!std::constructible_from<length<metre, min_impl<int>>, length<metre, double>>); // narrowing conversion
|
||||
static_assert(!std::convertible_to<length<metre, double>, length<metre, min_impl<int>>>);
|
||||
|
||||
// min_impl<T> -> T
|
||||
@@ -217,13 +221,14 @@ static_assert(std::convertible_to<length<metre, min_impl<double>>, length<metre,
|
||||
static_assert(std::constructible_from<length<metre, double>, length<metre, min_impl<int>>>);
|
||||
static_assert(std::convertible_to<length<metre, min_impl<int>>, length<metre, double>>);
|
||||
|
||||
static_assert(!std::constructible_from<length<metre, int>, length<metre, min_impl<double>>>); // narrowing conversion
|
||||
static_assert(!std::constructible_from<length<metre, int>, length<metre, min_impl<double>>>); // narrowing conversion
|
||||
static_assert(!std::convertible_to<length<metre, min_impl<double>>, length<metre, int>>);
|
||||
|
||||
|
||||
// arithmetic operators
|
||||
static_assert(length<metre, min_impl<int>>(1) + length<metre, min_impl<int>>(1) == length<metre, min_impl<int>>(2));
|
||||
static_assert(length<metre, min_impl<int>>(1) + length<metre, min_impl<double>>(1.5) == length<metre, min_impl<double>>(2.5));
|
||||
static_assert(length<metre, min_impl<int>>(1) + length<metre, min_impl<double>>(1.5) ==
|
||||
length<metre, min_impl<double>>(2.5));
|
||||
static_assert(length<metre, int>(1) + length<metre, min_impl<int>>(1) == length<metre, min_impl<int>>(2));
|
||||
static_assert(length<metre, int>(1) + length<metre, min_impl<double>>(1.5) == length<metre, min_impl<double>>(2.5));
|
||||
static_assert(length<metre, min_impl<int>>(1) + length<metre, int>(1) == length<metre, min_impl<int>>(2));
|
||||
@@ -231,26 +236,37 @@ static_assert(length<metre, min_impl<int>>(1) + length<metre, double>(1.5) == le
|
||||
static_assert(length<metre, min_impl<int>>(1) + length<metre, min_impl<int>>(1) == length<metre, int>(2));
|
||||
static_assert(length<metre, min_impl<int>>(1) + length<metre, min_impl<double>>(1.5) == length<metre, double>(2.5));
|
||||
|
||||
static_assert(length<kilometre, min_impl<int>>(1) + length<metre, min_impl<int>>(1) == length<metre, min_impl<int>>(1001));
|
||||
static_assert(length<kilometre, min_impl<int>>(1) + length<metre, min_impl<double>>(1.5) == length<metre, min_impl<double>>(1001.5));
|
||||
static_assert(length<kilometre, min_impl<int>>(1) + length<metre, min_impl<int>>(1) ==
|
||||
length<metre, min_impl<int>>(1001));
|
||||
static_assert(length<kilometre, min_impl<int>>(1) + length<metre, min_impl<double>>(1.5) ==
|
||||
length<metre, min_impl<double>>(1001.5));
|
||||
static_assert(length<kilometre, int>(1) + length<metre, min_impl<int>>(1) == length<metre, min_impl<int>>(1001));
|
||||
static_assert(length<kilometre, int>(1) + length<metre, min_impl<double>>(1.5) == length<metre, min_impl<double>>(1001.5));
|
||||
static_assert(length<kilometre, int>(1) + length<metre, min_impl<double>>(1.5) ==
|
||||
length<metre, min_impl<double>>(1001.5));
|
||||
static_assert(length<kilometre, min_impl<int>>(1) + length<metre, int>(1) == length<metre, min_impl<int>>(1001));
|
||||
static_assert(length<kilometre, min_impl<int>>(1) + length<metre, double>(1.5) == length<metre, min_impl<double>>(1001.5));
|
||||
static_assert(length<kilometre, min_impl<int>>(1) + length<metre, double>(1.5) ==
|
||||
length<metre, min_impl<double>>(1001.5));
|
||||
static_assert(length<kilometre, min_impl<int>>(1) + length<metre, min_impl<int>>(1) == length<metre, int>(1001));
|
||||
static_assert(length<kilometre, min_impl<int>>(1) + length<metre, min_impl<double>>(1.5) == length<metre, double>(1001.5));
|
||||
static_assert(length<kilometre, min_impl<int>>(1) + length<metre, min_impl<double>>(1.5) ==
|
||||
length<metre, double>(1001.5));
|
||||
|
||||
static_assert(length<metre, min_impl<int>>(1) + length<kilometre, min_impl<int>>(1) == length<metre, min_impl<int>>(1001));
|
||||
static_assert(length<metre, min_impl<int>>(1) + length<kilometre, min_impl<double>>(1.5) == length<metre, min_impl<double>>(1501));
|
||||
static_assert(length<metre, min_impl<int>>(1) + length<kilometre, min_impl<int>>(1) ==
|
||||
length<metre, min_impl<int>>(1001));
|
||||
static_assert(length<metre, min_impl<int>>(1) + length<kilometre, min_impl<double>>(1.5) ==
|
||||
length<metre, min_impl<double>>(1501));
|
||||
static_assert(length<metre, int>(1) + length<kilometre, min_impl<int>>(1) == length<metre, min_impl<int>>(1001));
|
||||
static_assert(length<metre, int>(1) + length<kilometre, min_impl<double>>(1.5) == length<metre, min_impl<double>>(1501));
|
||||
static_assert(length<metre, int>(1) + length<kilometre, min_impl<double>>(1.5) ==
|
||||
length<metre, min_impl<double>>(1501));
|
||||
static_assert(length<metre, min_impl<int>>(1) + length<kilometre, int>(1) == length<metre, min_impl<int>>(1001));
|
||||
static_assert(length<metre, min_impl<int>>(1) + length<kilometre, double>(1.5) == length<metre, min_impl<double>>(1501));
|
||||
static_assert(length<metre, min_impl<int>>(1) + length<kilometre, double>(1.5) ==
|
||||
length<metre, min_impl<double>>(1501));
|
||||
static_assert(length<metre, min_impl<int>>(1) + length<kilometre, min_impl<int>>(1) == length<metre, int>(1001));
|
||||
static_assert(length<metre, min_impl<int>>(1) + length<kilometre, min_impl<double>>(1.5) == length<metre, double>(1501));
|
||||
static_assert(length<metre, min_impl<int>>(1) + length<kilometre, min_impl<double>>(1.5) ==
|
||||
length<metre, double>(1501));
|
||||
|
||||
static_assert(length<metre, min_impl<int>>(2) - length<metre, min_impl<int>>(1) == length<metre, min_impl<int>>(1));
|
||||
static_assert(length<metre, min_impl<int>>(2) - length<metre, min_impl<double>>(1.5) == length<metre, min_impl<double>>(0.5));
|
||||
static_assert(length<metre, min_impl<int>>(2) - length<metre, min_impl<double>>(1.5) ==
|
||||
length<metre, min_impl<double>>(0.5));
|
||||
static_assert(length<metre, int>(2) - length<metre, min_impl<int>>(1) == length<metre, min_impl<int>>(1));
|
||||
static_assert(length<metre, int>(2) - length<metre, min_impl<double>>(1.5) == length<metre, min_impl<double>>(0.5));
|
||||
static_assert(length<metre, min_impl<int>>(2) - length<metre, int>(1) == length<metre, min_impl<int>>(1));
|
||||
@@ -258,29 +274,40 @@ static_assert(length<metre, min_impl<int>>(2) - length<metre, double>(1.5) == le
|
||||
static_assert(length<metre, min_impl<int>>(2) - length<metre, min_impl<int>>(1) == length<metre, int>(1));
|
||||
static_assert(length<metre, min_impl<int>>(2) - length<metre, min_impl<double>>(1.5) == length<metre, double>(0.5));
|
||||
|
||||
static_assert(length<kilometre, min_impl<int>>(2) - length<metre, min_impl<int>>(1) == length<metre, min_impl<int>>(1999));
|
||||
static_assert(length<kilometre, min_impl<int>>(2) - length<metre, min_impl<double>>(1.5) == length<metre, min_impl<double>>(1998.5));
|
||||
static_assert(length<kilometre, min_impl<int>>(2) - length<metre, min_impl<int>>(1) ==
|
||||
length<metre, min_impl<int>>(1999));
|
||||
static_assert(length<kilometre, min_impl<int>>(2) - length<metre, min_impl<double>>(1.5) ==
|
||||
length<metre, min_impl<double>>(1998.5));
|
||||
static_assert(length<kilometre, int>(2) - length<metre, min_impl<int>>(1) == length<metre, min_impl<int>>(1999));
|
||||
static_assert(length<kilometre, int>(2) - length<metre, min_impl<double>>(1.5) == length<metre, min_impl<double>>(1998.5));
|
||||
static_assert(length<kilometre, int>(2) - length<metre, min_impl<double>>(1.5) ==
|
||||
length<metre, min_impl<double>>(1998.5));
|
||||
static_assert(length<kilometre, min_impl<int>>(2) - length<metre, int>(1) == length<metre, min_impl<int>>(1999));
|
||||
static_assert(length<kilometre, min_impl<int>>(2) - length<metre, double>(1.5) == length<metre, min_impl<double>>(1998.5));
|
||||
static_assert(length<kilometre, min_impl<int>>(2) - length<metre, double>(1.5) ==
|
||||
length<metre, min_impl<double>>(1998.5));
|
||||
static_assert(length<kilometre, min_impl<int>>(2) - length<metre, min_impl<int>>(1) == length<metre, int>(1999));
|
||||
static_assert(length<kilometre, min_impl<int>>(2) - length<metre, min_impl<double>>(1.5) == length<metre, double>(1998.5));
|
||||
static_assert(length<kilometre, min_impl<int>>(2) - length<metre, min_impl<double>>(1.5) ==
|
||||
length<metre, double>(1998.5));
|
||||
|
||||
static_assert(length<metre, min_impl<int>>(2000) - length<kilometre, min_impl<int>>(1) == length<metre, min_impl<int>>(1000));
|
||||
static_assert(length<metre, min_impl<int>>(2000) - length<kilometre, min_impl<double>>(1.5) == length<metre, min_impl<double>>(500));
|
||||
static_assert(length<metre, min_impl<int>>(2000) - length<kilometre, min_impl<int>>(1) ==
|
||||
length<metre, min_impl<int>>(1000));
|
||||
static_assert(length<metre, min_impl<int>>(2000) - length<kilometre, min_impl<double>>(1.5) ==
|
||||
length<metre, min_impl<double>>(500));
|
||||
static_assert(length<metre, int>(2000) - length<kilometre, min_impl<int>>(1) == length<metre, min_impl<int>>(1000));
|
||||
static_assert(length<metre, int>(2000) - length<kilometre, min_impl<double>>(1.5) == length<metre, min_impl<double>>(500));
|
||||
static_assert(length<metre, int>(2000) - length<kilometre, min_impl<double>>(1.5) ==
|
||||
length<metre, min_impl<double>>(500));
|
||||
static_assert(length<metre, min_impl<int>>(2000) - length<kilometre, int>(1) == length<metre, min_impl<int>>(1000));
|
||||
static_assert(length<metre, min_impl<int>>(2000) - length<kilometre, double>(1.5) == length<metre, min_impl<double>>(500));
|
||||
static_assert(length<metre, min_impl<int>>(2000) - length<kilometre, double>(1.5) ==
|
||||
length<metre, min_impl<double>>(500));
|
||||
static_assert(length<metre, min_impl<int>>(2000) - length<kilometre, min_impl<int>>(1) == length<metre, int>(1000));
|
||||
static_assert(length<metre, min_impl<int>>(2000) - length<kilometre, min_impl<double>>(1.5) == length<metre, double>(500));
|
||||
static_assert(length<metre, min_impl<int>>(2000) - length<kilometre, min_impl<double>>(1.5) ==
|
||||
length<metre, double>(500));
|
||||
|
||||
static_assert(length<metre, min_impl<int>>(123) * min_impl<double>(1.5) == length<metre, min_impl<double>>(184.5));
|
||||
static_assert(length<metre, min_impl<int>>(123) * 1.5 == length<metre, min_impl<double>>(184.5));
|
||||
static_assert(length<metre, int>(123) * min_impl<double>(1.5) == length<metre, min_impl<double>>(184.5));
|
||||
|
||||
static_assert(length<metre, min_impl<int>>(123) * quantity{min_impl<double>(1.5)} == length<metre, min_impl<double>>(184.5));
|
||||
static_assert(length<metre, min_impl<int>>(123) * quantity{min_impl<double>(1.5)} ==
|
||||
length<metre, min_impl<double>>(184.5));
|
||||
static_assert(length<metre, min_impl<int>>(123) * quantity{1.5} == length<metre, min_impl<double>>(184.5));
|
||||
static_assert(length<metre, int>(123) * quantity{min_impl<double>(1.5)} == length<metre, min_impl<double>>(184.5));
|
||||
|
||||
@@ -288,7 +315,8 @@ static_assert(min_impl<double>(1.5) * length<metre, min_impl<int>>(123) == lengt
|
||||
static_assert(min_impl<double>(1.5) * length<metre, int>(123) == length<metre, min_impl<double>>(184.5));
|
||||
static_assert(1.5 * length<metre, min_impl<int>>(123) == length<metre, min_impl<double>>(184.5));
|
||||
|
||||
static_assert(quantity{min_impl<double>(1.5)} * length<metre, min_impl<int>>(123) == length<metre, min_impl<double>>(184.5));
|
||||
static_assert(quantity{min_impl<double>(1.5)} * length<metre, min_impl<int>>(123) ==
|
||||
length<metre, min_impl<double>>(184.5));
|
||||
static_assert(quantity{min_impl<double>(1.5)} * length<metre, int>(123) == length<metre, min_impl<double>>(184.5));
|
||||
static_assert(quantity{1.5} * length<metre, min_impl<int>>(123) == length<metre, min_impl<double>>(184.5));
|
||||
|
||||
@@ -296,7 +324,8 @@ static_assert(length<metre, min_impl<int>>(123) / min_impl<double>(2.) == length
|
||||
static_assert(length<metre, min_impl<int>>(123) / 2. == length<metre, min_impl<double>>(61.5));
|
||||
static_assert(length<metre, int>(123) / min_impl<double>(2.) == length<metre, min_impl<double>>(61.5));
|
||||
|
||||
static_assert(length<metre, min_impl<int>>(123) / quantity{min_impl<double>(2.)} == length<metre, min_impl<double>>(61.5));
|
||||
static_assert(length<metre, min_impl<int>>(123) / quantity{min_impl<double>(2.)} ==
|
||||
length<metre, min_impl<double>>(61.5));
|
||||
static_assert(length<metre, min_impl<int>>(123) / quantity{2.} == length<metre, min_impl<double>>(61.5));
|
||||
static_assert(length<metre, int>(123) / quantity{min_impl<double>(2.)} == length<metre, min_impl<double>>(61.5));
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include <units/isq/si/mass.h>
|
||||
#include <units/isq/si/time.h>
|
||||
#include <units/isq/si/voltage.h>
|
||||
#include <units/math.h> // IWYU pragma: keep
|
||||
#include <units/math.h> // IWYU pragma: keep
|
||||
#include <units/unit.h>
|
||||
|
||||
namespace {
|
||||
@@ -37,35 +37,43 @@ using namespace units::isq::si;
|
||||
|
||||
// power spectral density
|
||||
struct sq_volt_per_hertz : unit<sq_volt_per_hertz> {};
|
||||
struct dim_power_spectral_density : derived_dimension<dim_power_spectral_density, sq_volt_per_hertz, units::exponent<dim_voltage, 2>, units::exponent<dim_frequency, -1>> {};
|
||||
struct dim_power_spectral_density :
|
||||
derived_dimension<dim_power_spectral_density, sq_volt_per_hertz, units::exponent<dim_voltage, 2>,
|
||||
units::exponent<dim_frequency, -1>> {};
|
||||
|
||||
template<UnitOf<dim_power_spectral_density> U, Representation Rep = double>
|
||||
using power_spectral_density = quantity<dim_power_spectral_density, U, Rep>;
|
||||
|
||||
// amplitude spectral density
|
||||
struct volt_per_sqrt_hertz : unit<volt_per_sqrt_hertz> {};
|
||||
struct dim_amplitude_spectral_density : derived_dimension<dim_amplitude_spectral_density, volt_per_sqrt_hertz, units::exponent<dim_voltage, 1>, units::exponent<dim_frequency, -1, 2>> {};
|
||||
struct dim_amplitude_spectral_density :
|
||||
derived_dimension<dim_amplitude_spectral_density, volt_per_sqrt_hertz, units::exponent<dim_voltage, 1>,
|
||||
units::exponent<dim_frequency, -1, 2>> {};
|
||||
|
||||
template<UnitOf<dim_amplitude_spectral_density> U, Representation Rep = double>
|
||||
using amplitude_spectral_density = quantity<dim_amplitude_spectral_density, U, Rep>;
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace {
|
||||
|
||||
static_assert(compare<dimension_sqrt<dim_power_spectral_density>, dim_amplitude_spectral_density>);
|
||||
static_assert(compare<dimension_pow<dim_amplitude_spectral_density, 2>, dim_power_spectral_density>);
|
||||
|
||||
static_assert(compare<decltype(pow<2>(amplitude_spectral_density<volt_per_sqrt_hertz>(4))), decltype(power_spectral_density<sq_volt_per_hertz>(16))>);
|
||||
static_assert(compare<decltype(sqrt(power_spectral_density<sq_volt_per_hertz>(16))), decltype(amplitude_spectral_density<volt_per_sqrt_hertz>(4))>);
|
||||
static_assert(compare<decltype(pow<2>(amplitude_spectral_density<volt_per_sqrt_hertz>(4))),
|
||||
decltype(power_spectral_density<sq_volt_per_hertz>(16))>);
|
||||
static_assert(compare<decltype(sqrt(power_spectral_density<sq_volt_per_hertz>(16))),
|
||||
decltype(amplitude_spectral_density<volt_per_sqrt_hertz>(4))>);
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace {
|
||||
|
||||
struct kilogram_per_second : unit<kilogram_per_second> {};
|
||||
struct dim_mass_rate : derived_dimension<dim_mass_rate, kilogram_per_second, units::exponent<dim_mass, 1>, units::exponent<dim_time, -1>> {};
|
||||
struct dim_mass_rate :
|
||||
derived_dimension<dim_mass_rate, kilogram_per_second, units::exponent<dim_mass, 1>, units::exponent<dim_time, -1>> {
|
||||
};
|
||||
struct kilogram_per_hour : derived_unit<kilogram_per_hour, dim_mass_rate, kilogram, hour> {};
|
||||
[[maybe_unused]] constexpr auto a = 1_q_kg / 1_q_h;
|
||||
|
||||
}
|
||||
} // namespace
|
||||
@@ -20,9 +20,9 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/bits/dimension_op.h>
|
||||
#include <units/base_dimension.h>
|
||||
#include <units/bits/dim_unpack.h>
|
||||
#include <units/bits/dimension_op.h>
|
||||
#include <units/derived_dimension.h>
|
||||
#include <units/unit.h>
|
||||
|
||||
@@ -54,18 +54,21 @@ using derived_dim = detail::derived_dimension_base<Es...>;
|
||||
|
||||
static_assert(is_same_v<dim_unpack<>, exponent_list<>>);
|
||||
static_assert(is_same_v<dim_unpack<units::exponent<d0, 1>>, exponent_list<units::exponent<d0, 1>>>);
|
||||
static_assert(is_same_v<dim_unpack<units::exponent<d0, 1>, units::exponent<d1, 2>>, exponent_list<units::exponent<d0, 1>, units::exponent<d1, 2>>>);
|
||||
static_assert(is_same_v<dim_unpack<units::exponent<d0, 1>, units::exponent<d1, 2>>,
|
||||
exponent_list<units::exponent<d0, 1>, units::exponent<d1, 2>>>);
|
||||
using dim1 = derived_dim<units::exponent<d0, 1>>;
|
||||
using dim2 = derived_dim<units::exponent<d0, 1>, units::exponent<d1, 2>>;
|
||||
static_assert(is_same_v<dim_unpack<units::exponent<dim1, 2>, units::exponent<d0, 1>>, exponent_list<units::exponent<d0, 2>, units::exponent<d0, 1>>>);
|
||||
static_assert(is_same_v<dim_unpack<units::exponent<dim1, 2>, units::exponent<d0, 1>>,
|
||||
exponent_list<units::exponent<d0, 2>, units::exponent<d0, 1>>>);
|
||||
static_assert(is_same_v<dim_unpack<units::exponent<dim2, -2>, units::exponent<d0, 1>, units::exponent<d1, 2>>,
|
||||
exponent_list<units::exponent<d0, -2>, units::exponent<d1, -4>, units::exponent<d0, 1>, units::exponent<d1, 2>>>);
|
||||
exponent_list<units::exponent<d0, -2>, units::exponent<d1, -4>, units::exponent<d0, 1>,
|
||||
units::exponent<d1, 2>>>);
|
||||
|
||||
// dim_invert
|
||||
static_assert(is_same_v<dim_invert<derived_dim<units::exponent<d0, -1>>>, d0>);
|
||||
static_assert(is_same_v<dim_invert<derived_dim<units::exponent<d0, -2>>>, unknown_dimension<units::exponent<d0, 2>>>);
|
||||
static_assert(
|
||||
is_same_v<dim_invert<derived_dim<units::exponent<d0, 2>, units::exponent<d1, -1>>>, unknown_dimension<units::exponent<d0, -2>, units::exponent<d1, 1>>>);
|
||||
static_assert(is_same_v<dim_invert<derived_dim<units::exponent<d0, 2>, units::exponent<d1, -1>>>,
|
||||
unknown_dimension<units::exponent<d0, -2>, units::exponent<d1, 1>>>);
|
||||
|
||||
// make_dimension
|
||||
|
||||
@@ -73,46 +76,63 @@ template<typename... Ts>
|
||||
using make_dimension = detail::make_dimension<Ts...>;
|
||||
|
||||
static_assert(is_same_v<make_dimension<units::exponent<d0, 1>>, derived_dim<units::exponent<d0, 1>>>);
|
||||
static_assert(is_same_v<make_dimension<units::exponent<d0, 1>, units::exponent<d1, 1>>, derived_dim<units::exponent<d0, 1>, units::exponent<d1, 1>>>);
|
||||
static_assert(is_same_v<make_dimension<units::exponent<d1, 1>, units::exponent<d0, 1>>, derived_dim<units::exponent<d0, 1>, units::exponent<d1, 1>>>);
|
||||
static_assert(is_same_v<make_dimension<units::exponent<d1, 1>, units::exponent<d1, 1>>, derived_dim<units::exponent<d1, 2>>>);
|
||||
static_assert(is_same_v<make_dimension<units::exponent<d1, 1>, units::exponent<d1, 1, 2>>, derived_dim<units::exponent<d1, 3, 2>>>);
|
||||
static_assert(is_same_v<make_dimension<units::exponent<d1, 1, 2>, units::exponent<d1, 1, 2>>, derived_dim<units::exponent<d1, 1>>>);
|
||||
static_assert(is_same_v<make_dimension<units::exponent<d1, 2>, units::exponent<d1, 1, 2>>, derived_dim<units::exponent<d1, 5, 2>>>);
|
||||
static_assert(is_same_v<make_dimension<units::exponent<d0, 1>, units::exponent<d1, 1>>,
|
||||
derived_dim<units::exponent<d0, 1>, units::exponent<d1, 1>>>);
|
||||
static_assert(is_same_v<make_dimension<units::exponent<d1, 1>, units::exponent<d0, 1>>,
|
||||
derived_dim<units::exponent<d0, 1>, units::exponent<d1, 1>>>);
|
||||
static_assert(
|
||||
is_same_v<make_dimension<units::exponent<d1, 1>, units::exponent<d1, 1>>, derived_dim<units::exponent<d1, 2>>>);
|
||||
static_assert(
|
||||
is_same_v<make_dimension<units::exponent<d1, 1>, units::exponent<d1, 1, 2>>, derived_dim<units::exponent<d1, 3, 2>>>);
|
||||
static_assert(
|
||||
is_same_v<make_dimension<units::exponent<d1, 1, 2>, units::exponent<d1, 1, 2>>, derived_dim<units::exponent<d1, 1>>>);
|
||||
static_assert(
|
||||
is_same_v<make_dimension<units::exponent<d1, 2>, units::exponent<d1, 1, 2>>, derived_dim<units::exponent<d1, 5, 2>>>);
|
||||
|
||||
static_assert(is_same_v<make_dimension<units::exponent<d0, 1>, units::exponent<d1, 1>, units::exponent<d0, 1>, units::exponent<d1, 1>>,
|
||||
derived_dim<units::exponent<d0, 2>, units::exponent<d1, 2>>>);
|
||||
static_assert(is_same_v<make_dimension<units::exponent<d0, -1>, units::exponent<d1, -1>, units::exponent<d0, -1>, units::exponent<d1, -1>>,
|
||||
derived_dim<units::exponent<d0, -2>, units::exponent<d1, -2>>>);
|
||||
static_assert(is_same_v<make_dimension<units::exponent<d0, 1>, units::exponent<d1, 1>, units::exponent<d0, 1>,
|
||||
units::exponent<d1, 1>>,
|
||||
derived_dim<units::exponent<d0, 2>, units::exponent<d1, 2>>>);
|
||||
static_assert(is_same_v<make_dimension<units::exponent<d0, -1>, units::exponent<d1, -1>, units::exponent<d0, -1>,
|
||||
units::exponent<d1, -1>>,
|
||||
derived_dim<units::exponent<d0, -2>, units::exponent<d1, -2>>>);
|
||||
|
||||
static_assert(is_same_v<make_dimension<units::exponent<d0, 1>, units::exponent<d1, 1>, units::exponent<d1, -1>>, derived_dim<units::exponent<d0, 1>>>);
|
||||
static_assert(is_same_v<make_dimension<units::exponent<d0, 1>, units::exponent<d0, -1>, units::exponent<d1, 1>>, derived_dim<units::exponent<d1, 1>>>);
|
||||
static_assert(is_same_v<make_dimension<units::exponent<d0, 1>, units::exponent<d1, 1>, units::exponent<d0, -1>>, derived_dim<units::exponent<d1, 1>>>);
|
||||
static_assert(is_same_v<make_dimension<units::exponent<d0, 1>, units::exponent<d1, 1>, units::exponent<d1, -1>>,
|
||||
derived_dim<units::exponent<d0, 1>>>);
|
||||
static_assert(is_same_v<make_dimension<units::exponent<d0, 1>, units::exponent<d0, -1>, units::exponent<d1, 1>>,
|
||||
derived_dim<units::exponent<d1, 1>>>);
|
||||
static_assert(is_same_v<make_dimension<units::exponent<d0, 1>, units::exponent<d1, 1>, units::exponent<d0, -1>>,
|
||||
derived_dim<units::exponent<d1, 1>>>);
|
||||
|
||||
// dimension_multiply
|
||||
|
||||
static_assert(is_same_v<dimension_multiply<derived_dim<units::exponent<d0, 1>>, derived_dim<units::exponent<d1, 1>>>,
|
||||
unknown_dimension<units::exponent<d0, 1>, units::exponent<d1, 1>>>);
|
||||
static_assert(
|
||||
is_same_v<dimension_multiply<derived_dim<units::exponent<d0, 1>>, d1>, unknown_dimension<units::exponent<d0, 1>, units::exponent<d1, 1>>>);
|
||||
static_assert(
|
||||
is_same_v<dimension_multiply<d0, derived_dim<units::exponent<d1, 1>>>, unknown_dimension<units::exponent<d0, 1>, units::exponent<d1, 1>>>);
|
||||
unknown_dimension<units::exponent<d0, 1>, units::exponent<d1, 1>>>);
|
||||
static_assert(is_same_v<dimension_multiply<derived_dim<units::exponent<d0, 1>>, d1>,
|
||||
unknown_dimension<units::exponent<d0, 1>, units::exponent<d1, 1>>>);
|
||||
static_assert(is_same_v<dimension_multiply<d0, derived_dim<units::exponent<d1, 1>>>,
|
||||
unknown_dimension<units::exponent<d0, 1>, units::exponent<d1, 1>>>);
|
||||
static_assert(is_same_v<dimension_multiply<d0, d1>, unknown_dimension<units::exponent<d0, 1>, units::exponent<d1, 1>>>);
|
||||
static_assert(is_same_v<
|
||||
dimension_multiply<derived_dim<units::exponent<d0, 1>, units::exponent<d1, 1>, units::exponent<d2, 1>>, derived_dim<units::exponent<d3, 1>>>,
|
||||
unknown_dimension<units::exponent<d0, 1>, units::exponent<d1, 1>, units::exponent<d2, 1>, units::exponent<d3, 1>>>);
|
||||
static_assert(is_same_v<
|
||||
dimension_multiply<derived_dim<units::exponent<d0, 1>, units::exponent<d1, 1>, units::exponent<d2, 1>>, derived_dim<units::exponent<d1, 1>>>,
|
||||
unknown_dimension<units::exponent<d0, 1>, units::exponent<d1, 2>, units::exponent<d2, 1>>>);
|
||||
static_assert(is_same_v<
|
||||
dimension_multiply<derived_dim<units::exponent<d0, 1>, units::exponent<d1, 1>, units::exponent<d2, 1>>, derived_dim<units::exponent<d1, -1>>>,
|
||||
unknown_dimension<units::exponent<d0, 1>, units::exponent<d2, 1>>>);
|
||||
static_assert(is_same_v<dimension_multiply<derived_dim<units::exponent<d0, 2>>, derived_dim<units::exponent<d0, -1>>>, d0>);
|
||||
static_assert(
|
||||
is_same_v<
|
||||
dimension_multiply<derived_dim<units::exponent<d0, 1>, units::exponent<d1, 1>, units::exponent<d2, 1>>,
|
||||
derived_dim<units::exponent<d3, 1>>>,
|
||||
unknown_dimension<units::exponent<d0, 1>, units::exponent<d1, 1>, units::exponent<d2, 1>, units::exponent<d3, 1>>>);
|
||||
static_assert(
|
||||
is_same_v<dimension_multiply<derived_dim<units::exponent<d0, 1>, units::exponent<d1, 1>, units::exponent<d2, 1>>,
|
||||
derived_dim<units::exponent<d1, 1>>>,
|
||||
unknown_dimension<units::exponent<d0, 1>, units::exponent<d1, 2>, units::exponent<d2, 1>>>);
|
||||
static_assert(
|
||||
is_same_v<dimension_multiply<derived_dim<units::exponent<d0, 1>, units::exponent<d1, 1>, units::exponent<d2, 1>>,
|
||||
derived_dim<units::exponent<d1, -1>>>,
|
||||
unknown_dimension<units::exponent<d0, 1>, units::exponent<d2, 1>>>);
|
||||
static_assert(
|
||||
is_same_v<dimension_multiply<derived_dim<units::exponent<d0, 2>>, derived_dim<units::exponent<d0, -1>>>, d0>);
|
||||
|
||||
// dimension_divide
|
||||
|
||||
static_assert(is_same_v<dimension_divide<derived_dim<units::exponent<d0, 1>>, derived_dim<units::exponent<d1, 1>>>,
|
||||
unknown_dimension<units::exponent<d0, 1>, units::exponent<d1, -1>>>);
|
||||
static_assert(is_same_v<dimension_divide<derived_dim<units::exponent<d0, 2>>, unknown_dimension<units::exponent<d0, 1>>>, d0>);
|
||||
unknown_dimension<units::exponent<d0, 1>, units::exponent<d1, -1>>>);
|
||||
static_assert(
|
||||
is_same_v<dimension_divide<derived_dim<units::exponent<d0, 2>>, unknown_dimension<units::exponent<d0, 1>>>, d0>);
|
||||
|
||||
} // namespace
|
||||
@@ -58,4 +58,4 @@ static_assert(120 * kB / (2 * min) == 1000 * (B / s));
|
||||
static_assert(12 / (2 * s) == 6 * Bd);
|
||||
static_assert(6000 / (3 * s) == 2 * kBd);
|
||||
|
||||
}
|
||||
} // namespace
|
||||
@@ -21,14 +21,14 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "test_tools.h"
|
||||
#include <units/math.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/length.h>
|
||||
#include <units/isq/si/area.h>
|
||||
#include <units/isq/si/volume.h>
|
||||
#include <units/isq/si/time.h>
|
||||
#include <units/isq/si/international/length.h>
|
||||
#include <units/isq/si/international/area.h>
|
||||
#include <units/isq/si/international/length.h>
|
||||
#include <units/isq/si/international/volume.h>
|
||||
#include <units/isq/si/length.h>
|
||||
#include <units/isq/si/time.h>
|
||||
#include <units/isq/si/volume.h>
|
||||
#include <units/math.h> // IWYU pragma: keep
|
||||
|
||||
namespace {
|
||||
|
||||
|
||||
@@ -22,10 +22,10 @@
|
||||
|
||||
#include <units/bits/equivalent.h>
|
||||
#include <units/chrono.h>
|
||||
#include <units/isq/si/cgs/length.h>
|
||||
#include <units/isq/si/length.h>
|
||||
#include <units/kind.h>
|
||||
#include <units/quantity_point.h>
|
||||
#include <units/isq/si/length.h>
|
||||
#include <units/isq/si/cgs/length.h>
|
||||
|
||||
using namespace units;
|
||||
namespace si = isq::si;
|
||||
@@ -54,8 +54,8 @@ static_assert(RebindablePointOriginFor<dynamic_origin<si::dim_length>, si::dim_l
|
||||
static_assert(is_same_v<rebind_point_origin_dimension<dynamic_origin<si::dim_length>, si::dim_length>,
|
||||
dynamic_origin<si::dim_length>>);
|
||||
static_assert(RebindablePointOriginFor<dynamic_origin<si::dim_length>, si::dim_time>);
|
||||
static_assert(is_same_v<rebind_point_origin_dimension<dynamic_origin<si::dim_length>, si::dim_time>,
|
||||
dynamic_origin<si::dim_time>>);
|
||||
static_assert(
|
||||
is_same_v<rebind_point_origin_dimension<dynamic_origin<si::dim_length>, si::dim_time>, dynamic_origin<si::dim_time>>);
|
||||
static_assert(RebindablePointOriginFor<ones_viewpoint1, si::dim_length>);
|
||||
static_assert(is_same_v<rebind_point_origin_dimension<ones_viewpoint1, si::dim_length>, ones_viewpoint1>);
|
||||
static_assert(RebindablePointOriginFor<ones_viewpoint2, si::dim_length>);
|
||||
|
||||
@@ -62,17 +62,25 @@ struct time_kind : kind<time_kind, dim_time> {};
|
||||
|
||||
struct cgs_width_kind : kind<cgs_width_kind, cgs::dim_length> {};
|
||||
|
||||
template <Unit U, Representation Rep = double> using radius = quantity_kind<radius_kind, U, Rep>;
|
||||
template <Unit U, Representation Rep = double> using width = quantity_kind<width_kind, U, Rep>;
|
||||
template <Unit U, Representation Rep = double> using height = quantity_kind<height_kind, U, Rep>;
|
||||
template<Unit U, Representation Rep = double>
|
||||
using radius = quantity_kind<radius_kind, U, Rep>;
|
||||
template<Unit U, Representation Rep = double>
|
||||
using width = quantity_kind<width_kind, U, Rep>;
|
||||
template<Unit U, Representation Rep = double>
|
||||
using height = quantity_kind<height_kind, U, Rep>;
|
||||
|
||||
template <Unit U, Representation Rep = double> using horizontal_area = quantity_kind<horizontal_area_kind, U, Rep>;
|
||||
template <Unit U, Representation Rep = double> using rate_of_climb = quantity_kind<rate_of_climb_kind, U, Rep>;
|
||||
template<Unit U, Representation Rep = double>
|
||||
using horizontal_area = quantity_kind<horizontal_area_kind, U, Rep>;
|
||||
template<Unit U, Representation Rep = double>
|
||||
using rate_of_climb = quantity_kind<rate_of_climb_kind, U, Rep>;
|
||||
|
||||
template <Unit U = one, Representation Rep = double> using apples = quantity_kind<apple, U, Rep>;
|
||||
template <Unit U = one, Representation Rep = double> using oranges = quantity_kind<orange, U, Rep>;
|
||||
template<Unit U = one, Representation Rep = double>
|
||||
using apples = quantity_kind<apple, U, Rep>;
|
||||
template<Unit U = one, Representation Rep = double>
|
||||
using oranges = quantity_kind<orange, U, Rep>;
|
||||
|
||||
template <Unit U, Representation Rep = double> using cgs_width = quantity_kind<cgs_width_kind, U, Rep>;
|
||||
template<Unit U, Representation Rep = double>
|
||||
using cgs_width = quantity_kind<cgs_width_kind, U, Rep>;
|
||||
|
||||
/////////////
|
||||
// concepts
|
||||
@@ -102,14 +110,17 @@ static_assert(sizeof(width<metre, double>) == sizeof(double));
|
||||
static_assert(sizeof(height<metre, short>) == sizeof(short));
|
||||
|
||||
template<typename Width>
|
||||
concept invalid_types = requires {
|
||||
requires !requires { typename quantity_kind<Width, second, int>; }; // unit of a different dimension
|
||||
requires !requires { typename quantity_kind<Width, metre, length<metre>>; }; // quantity used as Rep
|
||||
requires !requires { typename quantity_kind<Width, metre, quantity_point<dynamic_origin<dim_length>, metre>>; }; // quantity point used as Rep
|
||||
requires !requires { typename quantity_kind<Width, metre, width<metre>>; }; // quantity kind used as Rep
|
||||
requires !requires { typename quantity_kind<metre, Width, double>; }; // reordered arguments
|
||||
requires !requires { typename quantity_kind<metre, double, Width>; }; // reordered arguments
|
||||
};
|
||||
concept invalid_types =
|
||||
requires {
|
||||
requires !requires { typename quantity_kind<Width, second, int>; }; // unit of a different dimension
|
||||
requires !requires { typename quantity_kind<Width, metre, length<metre>>; }; // quantity used as Rep
|
||||
requires !requires {
|
||||
typename quantity_kind<Width, metre, quantity_point<dynamic_origin<dim_length>, metre>>;
|
||||
}; // quantity point used as Rep
|
||||
requires !requires { typename quantity_kind<Width, metre, width<metre>>; }; // quantity kind used as Rep
|
||||
requires !requires { typename quantity_kind<metre, Width, double>; }; // reordered arguments
|
||||
requires !requires { typename quantity_kind<metre, double, Width>; }; // reordered arguments
|
||||
};
|
||||
static_assert(invalid_types<width_kind>);
|
||||
|
||||
static_assert(std::is_trivially_default_constructible_v<width<metre>>);
|
||||
@@ -199,7 +210,7 @@ static_assert(width<metre>{}.common() == 0 * m);
|
||||
/////////
|
||||
|
||||
static_assert(same(quantity_kind(rate_of_climb<kilometre_per_hour, double>(0.01 * (km / h))),
|
||||
rate_of_climb<kilometre_per_hour, double>(0.01 * (km / h))));
|
||||
rate_of_climb<kilometre_per_hour, double>(0.01 * (km / h))));
|
||||
|
||||
|
||||
////////////////////////////
|
||||
@@ -417,7 +428,8 @@ static_assert((std::uint8_t(255) * m %= quantity(257)) ==
|
||||
(width<metre, std::uint8_t>(255 * m) %= quantity(257)).common());
|
||||
static_assert((std::uint8_t(255) * m %= 257 * m) ==
|
||||
(width<metre, std::uint8_t>(255 * m) %=
|
||||
quantity_kind<downcast_kind<width_kind, dim_one>, one, std::uint8_t>(257)).common());
|
||||
quantity_kind<downcast_kind<width_kind, dim_one>, one, std::uint8_t>(257))
|
||||
.common());
|
||||
static_assert((std::uint8_t(255) * m %= 257 * m) ==
|
||||
(width<metre, std::uint8_t>(255 * m) %= width<metre, std::uint8_t>(257 * m)).common());
|
||||
|
||||
@@ -425,38 +437,39 @@ static_assert(same((-width<metre, short>(short{1} * m)).common(), int{-1} * m));
|
||||
|
||||
template<typename K, typename U, typename Qx>
|
||||
concept invalid_compound_assignments_ = requires(quantity_kind<K, U, int> w, Qx q) {
|
||||
requires !requires { w += q; };
|
||||
requires !requires { w -= q; };
|
||||
requires !requires { w *= q; };
|
||||
requires !requires { w /= q; };
|
||||
requires !requires { w %= q; };
|
||||
};
|
||||
requires !requires { w += q; };
|
||||
requires !requires { w -= q; };
|
||||
requires !requires { w *= q; };
|
||||
requires !requires { w /= q; };
|
||||
requires !requires { w %= q; };
|
||||
};
|
||||
template<typename Width>
|
||||
concept invalid_compound_assignments = requires(quantity_kind<Width, metre, int> w, height<metre, int> h) {
|
||||
requires !requires { w += 1; };
|
||||
requires !requires { w -= 1; };
|
||||
requires !requires { w *= 1 * (km / m); };
|
||||
requires !requires { w /= 1 * (km / m); };
|
||||
requires !requires { w %= 1 * (km / m); };
|
||||
requires !requires { w += m; };
|
||||
requires !requires { w -= m; };
|
||||
requires !requires { w *= m; };
|
||||
requires !requires { w /= m; };
|
||||
requires !requires { w %= m; };
|
||||
requires !requires { w *= quantity_kind<downcast_kind<Width, dim_one>, scaled_unit<ratio{1, 1, 3}, one>, int>{1}; };
|
||||
requires !requires { w /= quantity_kind<downcast_kind<Width, dim_one>, scaled_unit<ratio{1, 1, 3}, one>, int>{1}; };
|
||||
requires !requires { w %= quantity_kind<downcast_kind<Width, dim_one>, scaled_unit<ratio{1, 1, 3}, one>, int>{1}; };
|
||||
requires !requires { w %= 1.0; };
|
||||
requires !requires { w %= quantity(1.0); };
|
||||
requires !requires { w %= 1.0 * (w / w); };
|
||||
requires !requires { w %= 1.0 * w; };
|
||||
requires !requires { w %= h / h; };
|
||||
requires invalid_compound_assignments_<Width, metre, length<metre, int>>;
|
||||
requires invalid_compound_assignments_<Width, metre, height<metre, int>>;
|
||||
requires invalid_compound_assignments_<Width, metre, horizontal_area<square_metre, int>>;
|
||||
requires invalid_compound_assignments_<Width, metre, quantity_point<dynamic_origin<dim_length>, metre, int>>;
|
||||
requires invalid_compound_assignments_<Width, metre, std::chrono::seconds>;
|
||||
};
|
||||
concept invalid_compound_assignments =
|
||||
requires(quantity_kind<Width, metre, int> w, height<metre, int> h) {
|
||||
requires !requires { w += 1; };
|
||||
requires !requires { w -= 1; };
|
||||
requires !requires { w *= 1 * (km / m); };
|
||||
requires !requires { w /= 1 * (km / m); };
|
||||
requires !requires { w %= 1 * (km / m); };
|
||||
requires !requires { w += m; };
|
||||
requires !requires { w -= m; };
|
||||
requires !requires { w *= m; };
|
||||
requires !requires { w /= m; };
|
||||
requires !requires { w %= m; };
|
||||
requires !requires { w *= quantity_kind<downcast_kind<Width, dim_one>, scaled_unit<ratio{1, 1, 3}, one>, int>{1}; };
|
||||
requires !requires { w /= quantity_kind<downcast_kind<Width, dim_one>, scaled_unit<ratio{1, 1, 3}, one>, int>{1}; };
|
||||
requires !requires { w %= quantity_kind<downcast_kind<Width, dim_one>, scaled_unit<ratio{1, 1, 3}, one>, int>{1}; };
|
||||
requires !requires { w %= 1.0; };
|
||||
requires !requires { w %= quantity(1.0); };
|
||||
requires !requires { w %= 1.0 * (w / w); };
|
||||
requires !requires { w %= 1.0 * w; };
|
||||
requires !requires { w %= h / h; };
|
||||
requires invalid_compound_assignments_<Width, metre, length<metre, int>>;
|
||||
requires invalid_compound_assignments_<Width, metre, height<metre, int>>;
|
||||
requires invalid_compound_assignments_<Width, metre, horizontal_area<square_metre, int>>;
|
||||
requires invalid_compound_assignments_<Width, metre, quantity_point<dynamic_origin<dim_length>, metre, int>>;
|
||||
requires invalid_compound_assignments_<Width, metre, std::chrono::seconds>;
|
||||
};
|
||||
static_assert(invalid_compound_assignments<width_kind>);
|
||||
static_assert(invalid_compound_assignments_<time_kind, second, std::chrono::seconds>);
|
||||
|
||||
@@ -474,14 +487,16 @@ static_assert(same(width<metre, int>(2 * m) - width<metre, double>(3. * m), widt
|
||||
static_assert(same(width<metre, double>(2. * m) - width<metre, int>(3 * m), width<metre, double>(-1. * m)));
|
||||
static_assert(same(width<metre, double>(2e3 * m) - width<kilometre, int>(3 * km), width<metre, double>(-1e3 * m)));
|
||||
|
||||
static_assert(is_same_v<
|
||||
decltype((width<metre, std::uint8_t>(0 * m) + width<metre, std::uint8_t>(0 * m)).common().number()), int&&>);
|
||||
static_assert(is_same_v<
|
||||
decltype((width<metre, std::uint8_t>(0 * m) - width<metre, std::uint8_t>(0 * m)).common().number()), int&&>);
|
||||
static_assert(
|
||||
is_same_v<decltype((width<metre, std::uint8_t>(0 * m) + width<metre, std::uint8_t>(0 * m)).common().number()),
|
||||
int&&>);
|
||||
static_assert(
|
||||
is_same_v<decltype((width<metre, std::uint8_t>(0 * m) - width<metre, std::uint8_t>(0 * m)).common().number()),
|
||||
int&&>);
|
||||
static_assert((width<metre, std::uint8_t>(128 * m) + width<metre, std::uint8_t>(128 * m)).common().number() ==
|
||||
std::uint8_t(128) + std::uint8_t(128));
|
||||
std::uint8_t(128) + std::uint8_t(128));
|
||||
static_assert((width<metre, std::uint8_t>(0 * m) - width<metre, std::uint8_t>(1 * m)).common().number() ==
|
||||
std::uint8_t(0) - std::uint8_t(1));
|
||||
std::uint8_t(0) - std::uint8_t(1));
|
||||
|
||||
static_assert(!std::is_invocable_v<std::plus<>, width<metre>, double>);
|
||||
static_assert(!std::is_invocable_v<std::plus<>, width<metre>, length<metre>>);
|
||||
@@ -595,15 +610,15 @@ static_assert(same(quantity(2) / quantity_kind<time_kind, second, double>(3. * s
|
||||
static_assert(same(quantity(2.) / quantity_kind<time_kind, second, int>(3 * s),
|
||||
quantity_kind<downcast_kind<time_kind, dim_frequency>, hertz, double>(2 / 3. / (1 * s))));
|
||||
|
||||
static_assert(
|
||||
same(quantity_kind<downcast_kind<time_kind, dim_one>, one, int>(2) / quantity_kind<time_kind, second, int>(3 * s),
|
||||
quantity_kind<downcast_kind<time_kind, dim_frequency>, hertz, int>(2 / 3 / (1 * s))));
|
||||
static_assert(
|
||||
same(quantity_kind<downcast_kind<time_kind, dim_one>, one, int>(2) / quantity_kind<time_kind, second, double>(3. * s),
|
||||
quantity_kind<downcast_kind<time_kind, dim_frequency>, hertz, double>(2 / 3. / (1 * s))));
|
||||
static_assert(
|
||||
same(quantity_kind<downcast_kind<time_kind, dim_one>, one, double>(2.) / quantity_kind<time_kind, second, int>(3 * s),
|
||||
quantity_kind<downcast_kind<time_kind, dim_frequency>, hertz, double>(2 / 3. / (1 * s))));
|
||||
static_assert(same(quantity_kind<downcast_kind<time_kind, dim_one>, one, int>(2) /
|
||||
quantity_kind<time_kind, second, int>(3 * s),
|
||||
quantity_kind<downcast_kind<time_kind, dim_frequency>, hertz, int>(2 / 3 / (1 * s))));
|
||||
static_assert(same(quantity_kind<downcast_kind<time_kind, dim_one>, one, int>(2) /
|
||||
quantity_kind<time_kind, second, double>(3. * s),
|
||||
quantity_kind<downcast_kind<time_kind, dim_frequency>, hertz, double>(2 / 3. / (1 * s))));
|
||||
static_assert(same(quantity_kind<downcast_kind<time_kind, dim_one>, one, double>(2.) /
|
||||
quantity_kind<time_kind, second, int>(3 * s),
|
||||
quantity_kind<downcast_kind<time_kind, dim_frequency>, hertz, double>(2 / 3. / (1 * s))));
|
||||
|
||||
static_assert(same(height<metre, int>(2 * m) / (3 * s), rate_of_climb<metre_per_second, int>(0 * (m / s))));
|
||||
static_assert(same(height<metre, int>(2 * m) / (3. * s), rate_of_climb<metre_per_second, double>(2 / 3. * (m / s))));
|
||||
@@ -611,7 +626,8 @@ static_assert(same(height<metre, double>(2. * m) / (3 * s), rate_of_climb<metre_
|
||||
|
||||
static_assert(same(width<metre, int>(2 * m) * dimensionless<percent, int>(3), width<centimetre, int>(6 * cm)));
|
||||
static_assert(same(dimensionless<percent, int>(2) * width<metre, int>(3 * m), width<centimetre, int>(6 * cm)));
|
||||
static_assert(same(width<metre, int>(2 * m) / dimensionless<percent, double>(3), width<hectometre, double>(2. / 3 * hm)));
|
||||
static_assert(same(width<metre, int>(2 * m) / dimensionless<percent, double>(3),
|
||||
width<hectometre, double>(2. / 3 * hm)));
|
||||
static_assert(same(width<metre, int>(2 * m) % dimensionless<percent, int>(3), width<metre, int>(2 * m)));
|
||||
|
||||
static_assert(same(height<metre, int>(2 * m) / (3 * m),
|
||||
@@ -644,14 +660,16 @@ static_assert(same(horizontal_area<square_metre>(4 * (m * m)) / (1 * m), width<m
|
||||
static_assert(same(width<metre, int>(2 * m) % 3, width<metre, int>(2 * m)));
|
||||
static_assert(same(width<metre, int>(3 * m) % width<metre, int>(2 * m), width<metre, int>(1 * m)));
|
||||
|
||||
static_assert(is_same_v<
|
||||
decltype((width<metre, std::uint8_t>(0 * m) % width<metre, std::uint8_t>(0 * m)).common().number()),
|
||||
decltype(std::uint8_t(0) % std::uint8_t(0))&&>);
|
||||
static_assert(
|
||||
is_same_v<decltype((width<metre, std::uint8_t>(0 * m) % width<metre, std::uint8_t>(0 * m)).common().number()),
|
||||
decltype(std::uint8_t(0) % std::uint8_t(0))&&>);
|
||||
|
||||
static_assert(!std::is_invocable_v<std::multiplies<>, reference<dim_length, metre>, width<metre>>);
|
||||
static_assert(!std::is_invocable_v<std::multiplies<>, width<metre>, height<metre>>);
|
||||
static_assert(!std::is_invocable_v<std::multiplies<>, height<metre>, quantity_point<dynamic_origin<dim_length>, metre>>);
|
||||
static_assert(!std::is_invocable_v<std::multiplies<>, quantity_point<dynamic_origin<dim_length>, metre>, height<metre>>);
|
||||
static_assert(
|
||||
!std::is_invocable_v<std::multiplies<>, height<metre>, quantity_point<dynamic_origin<dim_length>, metre>>);
|
||||
static_assert(
|
||||
!std::is_invocable_v<std::multiplies<>, quantity_point<dynamic_origin<dim_length>, metre>, height<metre>>);
|
||||
|
||||
static_assert(!std::is_invocable_v<std::divides<>, reference<dim_length, metre>, width<metre>>);
|
||||
static_assert(!std::is_invocable_v<std::divides<>, width<metre>, height<metre>>);
|
||||
@@ -660,7 +678,8 @@ static_assert(!std::is_invocable_v<std::divides<>, quantity_point<dynamic_origin
|
||||
|
||||
static_assert(!std::is_invocable_v<std::modulus<>, width<metre, int>, reference<dim_length, metre>>);
|
||||
static_assert(!std::is_invocable_v<std::modulus<>, width<metre, int>, length<metre, int>>);
|
||||
static_assert(!std::is_invocable_v<std::modulus<>, width<metre, int>, quantity_point<dynamic_origin<dim_length>, metre, int>>);
|
||||
static_assert(
|
||||
!std::is_invocable_v<std::modulus<>, width<metre, int>, quantity_point<dynamic_origin<dim_length>, metre, int>>);
|
||||
static_assert(!std::is_invocable_v<std::modulus<>, width<metre, int>, double>);
|
||||
static_assert(!std::is_invocable_v<std::modulus<>, width<metre, int>, width<metre, double>>);
|
||||
|
||||
@@ -702,24 +721,24 @@ static_assert(std::equality_comparable_with<width<cgs::centimetre, int>, width<m
|
||||
static_assert(std::equality_comparable_with<width<metre>, width<cgs::centimetre>>);
|
||||
template<typename Width>
|
||||
concept invalid_equality = requires(quantity_kind<Width, metre, int> w) {
|
||||
requires !requires { w == 1; };
|
||||
requires !requires { w != 1.0; };
|
||||
requires !requires { w == 1 * m; };
|
||||
requires !requires { w != 1.0 * cgs_cm; };
|
||||
requires !requires { w == 1 * km; };
|
||||
requires !requires { w != m; };
|
||||
requires !requires { w == km; };
|
||||
requires !requires { w != quantity(1); };
|
||||
requires !requires { w == dimensionless<percent>(1.0); };
|
||||
requires !requires { w != height<metre, int>(1 * m); };
|
||||
requires !requires { w == height<kilometre, double>(1.0 * km); };
|
||||
requires !requires { w != horizontal_area<square_metre, int>(1 * (m * m)); };
|
||||
requires !requires { w == rate_of_climb<kilometre_per_hour, double>(1.0 * (km / h)); };
|
||||
requires !requires { w != quantity_point(1 * m); };
|
||||
requires !requires { w == quantity_point(1.0 * mm); };
|
||||
requires !requires { w != quantity_point(quantity(1)); };
|
||||
requires !requires { w == quantity_point(dimensionless<percent>(1.0)); };
|
||||
};
|
||||
requires !requires { w == 1; };
|
||||
requires !requires { w != 1.0; };
|
||||
requires !requires { w == 1 * m; };
|
||||
requires !requires { w != 1.0 * cgs_cm; };
|
||||
requires !requires { w == 1 * km; };
|
||||
requires !requires { w != m; };
|
||||
requires !requires { w == km; };
|
||||
requires !requires { w != quantity(1); };
|
||||
requires !requires { w == dimensionless<percent>(1.0); };
|
||||
requires !requires { w != height<metre, int>(1 * m); };
|
||||
requires !requires { w == height<kilometre, double>(1.0 * km); };
|
||||
requires !requires { w != horizontal_area<square_metre, int>(1 * (m * m)); };
|
||||
requires !requires { w == rate_of_climb<kilometre_per_hour, double>(1.0 * (km / h)); };
|
||||
requires !requires { w != quantity_point(1 * m); };
|
||||
requires !requires { w == quantity_point(1.0 * mm); };
|
||||
requires !requires { w != quantity_point(quantity(1)); };
|
||||
requires !requires { w == quantity_point(dimensionless<percent>(1.0)); };
|
||||
};
|
||||
static_assert(invalid_equality<width_kind>);
|
||||
|
||||
static_assert(width<metre, int>(1 * m) < width<metre, int>(2 * m));
|
||||
@@ -734,22 +753,22 @@ static_assert(std::three_way_comparable_with<width<cgs::centimetre, int>, width<
|
||||
static_assert(std::three_way_comparable_with<width<metre>, width<cgs::centimetre>>);
|
||||
template<typename Width>
|
||||
concept invalid_relational = requires(quantity_kind<Width, metre, int> w) {
|
||||
requires !requires { w < 1; };
|
||||
requires !requires { w <= 1.0; };
|
||||
requires !requires { w >= 1 * m; };
|
||||
requires !requires { w > 1.0 * cgs_cm; };
|
||||
requires !requires { w <=> 1 * km; };
|
||||
requires !requires { w < quantity(1); };
|
||||
requires !requires { w <= dimensionless<percent>(1.0); };
|
||||
requires !requires { w >= height<metre, int>(1 * m); };
|
||||
requires !requires { w > height<kilometre, double>(1.0 * km); };
|
||||
requires !requires { w <=> horizontal_area<square_metre, int>(1 * (m * m)); };
|
||||
requires !requires { w < rate_of_climb<kilometre_per_hour, double>(1.0 * (km / h)); };
|
||||
requires !requires { w <= quantity_point(1 * m); };
|
||||
requires !requires { w >= quantity_point(1.0 * mm); };
|
||||
requires !requires { w > quantity_point(quantity(1)); };
|
||||
requires !requires { w <=> quantity_point(dimensionless<percent>(1.0)); };
|
||||
};
|
||||
requires !requires { w < 1; };
|
||||
requires !requires { w <= 1.0; };
|
||||
requires !requires { w >= 1 * m; };
|
||||
requires !requires { w > 1.0 * cgs_cm; };
|
||||
requires !requires { w <=> 1 * km; };
|
||||
requires !requires { w < quantity(1); };
|
||||
requires !requires { w <= dimensionless<percent>(1.0); };
|
||||
requires !requires { w >= height<metre, int>(1 * m); };
|
||||
requires !requires { w > height<kilometre, double>(1.0 * km); };
|
||||
requires !requires { w <=> horizontal_area<square_metre, int>(1 * (m * m)); };
|
||||
requires !requires { w < rate_of_climb<kilometre_per_hour, double>(1.0 * (km / h)); };
|
||||
requires !requires { w <= quantity_point(1 * m); };
|
||||
requires !requires { w >= quantity_point(1.0 * mm); };
|
||||
requires !requires { w > quantity_point(quantity(1)); };
|
||||
requires !requires { w <=> quantity_point(dimensionless<percent>(1.0)); };
|
||||
};
|
||||
static_assert(invalid_relational<width_kind>);
|
||||
|
||||
|
||||
@@ -788,22 +807,37 @@ static_assert(same(quantity_kind_cast<length<centimetre, int>>(width<metre, doub
|
||||
static_assert(same(quantity_kind_cast<length<centimetre, int>>(width<cgs::centimetre, int>(1 * cgs_cm)), width<cgs::centimetre, int>(1 * cgs_cm)));
|
||||
// clang-format on
|
||||
template<typename Width>
|
||||
concept invalid_cast = requires {
|
||||
requires !requires { quantity_kind_cast<apples<one, int>>(quantity_kind<Width, metre, int>(1 * m)); };
|
||||
requires !requires { quantity_kind_cast<horizontal_area<square_metre, int>>(quantity_kind<Width, metre, int>(1 * m)); };
|
||||
requires !requires { quantity_kind_cast<rate_of_climb<metre_per_second, int>>(quantity_kind<Width, metre, int>(1 * m)); };
|
||||
requires !requires { quantity_kind_cast<apple>(quantity_kind<Width, metre, int>(1 * m)); };
|
||||
requires !requires { quantity_kind_cast<horizontal_area_kind>(quantity_kind<Width, metre, int>(1 * m)); };
|
||||
requires !requires { quantity_kind_cast<rate_of_climb_kind>(quantity_kind<Width, metre, int>(1 * m)); };
|
||||
requires !requires { quantity_kind_cast<apple, one>(quantity_kind<Width, metre, int>(1 * m)); };
|
||||
requires !requires { quantity_kind_cast<horizontal_area_kind, square_metre>(quantity_kind<Width, metre, int>(1 * m)); };
|
||||
requires !requires { quantity_kind_cast<rate_of_climb_kind, metre_per_second>(quantity_kind<Width, metre, int>(1 * m)); };
|
||||
requires !requires { quantity_kind_cast<dimensionless<one>>(quantity_kind<Width, metre, int>(1 * m)); };
|
||||
requires !requires { quantity_kind_cast<square_metre>(quantity_kind<Width, metre, int>(1 * m)); };
|
||||
requires !requires { quantity_kind_cast<second>(quantity_kind<Width, metre, int>(1 * m)); };
|
||||
requires !requires { quantity_kind_cast<quantity_point<dynamic_origin<dim_length>, metre, int>>(quantity_kind<Width, metre, int>(1 * m)); };
|
||||
requires !requires { quantity_kind_cast<quantity_point<dynamic_origin<dim_one>, one, int>>(quantity_kind<Width, metre, int>(1 * m)); };
|
||||
};
|
||||
concept invalid_cast =
|
||||
requires {
|
||||
requires !requires { quantity_kind_cast<apples<one, int>>(quantity_kind<Width, metre, int>(1 * m)); };
|
||||
requires !requires {
|
||||
quantity_kind_cast<horizontal_area<square_metre, int>>(quantity_kind<Width, metre, int>(1 * m));
|
||||
};
|
||||
requires !requires {
|
||||
quantity_kind_cast<rate_of_climb<metre_per_second, int>>(quantity_kind<Width, metre, int>(1 * m));
|
||||
};
|
||||
requires !requires { quantity_kind_cast<apple>(quantity_kind<Width, metre, int>(1 * m)); };
|
||||
requires !requires { quantity_kind_cast<horizontal_area_kind>(quantity_kind<Width, metre, int>(1 * m)); };
|
||||
requires !requires { quantity_kind_cast<rate_of_climb_kind>(quantity_kind<Width, metre, int>(1 * m)); };
|
||||
requires !requires { quantity_kind_cast<apple, one>(quantity_kind<Width, metre, int>(1 * m)); };
|
||||
requires !requires {
|
||||
quantity_kind_cast<horizontal_area_kind, square_metre>(quantity_kind<Width, metre, int>(1 * m));
|
||||
};
|
||||
requires !requires {
|
||||
quantity_kind_cast<rate_of_climb_kind, metre_per_second>(quantity_kind<Width, metre, int>(1 * m));
|
||||
};
|
||||
requires !requires { quantity_kind_cast<dimensionless<one>>(quantity_kind<Width, metre, int>(1 * m)); };
|
||||
requires !requires { quantity_kind_cast<square_metre>(quantity_kind<Width, metre, int>(1 * m)); };
|
||||
requires !requires { quantity_kind_cast<second>(quantity_kind<Width, metre, int>(1 * m)); };
|
||||
requires !requires {
|
||||
quantity_kind_cast<quantity_point<dynamic_origin<dim_length>, metre, int>>(
|
||||
quantity_kind<Width, metre, int>(1 * m));
|
||||
};
|
||||
requires !requires {
|
||||
quantity_kind_cast<quantity_point<dynamic_origin<dim_one>, one, int>>(
|
||||
quantity_kind<Width, metre, int>(1 * m));
|
||||
};
|
||||
};
|
||||
static_assert(invalid_cast<width_kind>);
|
||||
|
||||
|
||||
@@ -817,15 +851,15 @@ struct radius_kind : kind<radius_kind, si::dim_length> {};
|
||||
|
||||
struct cylinder_size {};
|
||||
|
||||
template <units::QuantityKindOf<radius_kind> Radius, units::QuantityKindOf<height_kind> Height>
|
||||
template<units::QuantityKindOf<radius_kind> Radius, units::QuantityKindOf<height_kind> Height>
|
||||
cylinder_size operator+(Radius, Height);
|
||||
|
||||
} // namespace mylib
|
||||
|
||||
namespace yourapp {
|
||||
|
||||
static_assert(is_same_v<mylib::cylinder_size,
|
||||
decltype(quantity_kind<mylib::radius_kind, metre, double>(1. * m) + height<metre, double>(1. * m))>);
|
||||
static_assert(is_same_v<mylib::cylinder_size, decltype(quantity_kind<mylib::radius_kind, metre, double>(1. * m) +
|
||||
height<metre, double>(1. * m))>);
|
||||
|
||||
} // namespace yourapp
|
||||
|
||||
|
||||
@@ -79,16 +79,25 @@ struct time_point_kind : point_kind<time_point_kind, time_kind> {};
|
||||
|
||||
struct sys_time_point_kind : point_kind<time_point_kind, time_kind, clock_origin<std::chrono::system_clock>> {};
|
||||
|
||||
template <Unit U, Representation Rep = double> using width = quantity_kind<width_kind, U, Rep>;
|
||||
template <Unit U, Representation Rep = double> using height = quantity_kind<height_kind, U, Rep>;
|
||||
template <Unit U, Representation Rep = double> using abscissa = quantity_point_kind<abscissa_kind, U, Rep>;
|
||||
template <Unit U, Representation Rep = double> using ordinate = quantity_point_kind<ordinate_kind, U, Rep>;
|
||||
template<Unit U, Representation Rep = double>
|
||||
using width = quantity_kind<width_kind, U, Rep>;
|
||||
template<Unit U, Representation Rep = double>
|
||||
using height = quantity_kind<height_kind, U, Rep>;
|
||||
template<Unit U, Representation Rep = double>
|
||||
using abscissa = quantity_point_kind<abscissa_kind, U, Rep>;
|
||||
template<Unit U, Representation Rep = double>
|
||||
using ordinate = quantity_point_kind<ordinate_kind, U, Rep>;
|
||||
|
||||
template <Unit U, Representation Rep = double> using distance = quantity_kind<distance_kind, U, Rep>;
|
||||
template <Unit U, Representation Rep = double> using cgs_width = quantity_kind<cgs_width_kind, U, Rep>;
|
||||
template <Unit U, Representation Rep = double> using cgs_height = quantity_kind<cgs_height_kind, U, Rep>;
|
||||
template <Unit U, Representation Rep = double> using rate_of_climb = quantity_kind<rate_of_climb_kind, U, Rep>;
|
||||
template <Unit U, Representation Rep = double> using altitude = quantity_point_kind<altitude_kind, U, Rep>;
|
||||
template<Unit U, Representation Rep = double>
|
||||
using distance = quantity_kind<distance_kind, U, Rep>;
|
||||
template<Unit U, Representation Rep = double>
|
||||
using cgs_width = quantity_kind<cgs_width_kind, U, Rep>;
|
||||
template<Unit U, Representation Rep = double>
|
||||
using cgs_height = quantity_kind<cgs_height_kind, U, Rep>;
|
||||
template<Unit U, Representation Rep = double>
|
||||
using rate_of_climb = quantity_kind<rate_of_climb_kind, U, Rep>;
|
||||
template<Unit U, Representation Rep = double>
|
||||
using altitude = quantity_point_kind<altitude_kind, U, Rep>;
|
||||
|
||||
template<Unit U, Representation Rep = double>
|
||||
using sea_level_altitude = quantity_point_kind<sea_level_altitude_kind, U, Rep>;
|
||||
@@ -97,10 +106,14 @@ using screen_si_width = quantity_point_kind<screen_si_width_kind, U, Rep>;
|
||||
template<Unit U, Representation Rep = double>
|
||||
using screen_si_cgs_width = quantity_point_kind<screen_si_cgs_width_kind, U, Rep>;
|
||||
|
||||
template <Unit U = one, Representation Rep = double> using apples = quantity_kind<apple, U, Rep>;
|
||||
template <Unit U = one, Representation Rep = double> using oranges = quantity_kind<orange, U, Rep>;
|
||||
template <Unit U = one, Representation Rep = double> using nth_apple = quantity_point_kind<nth_apple_kind, U, Rep>;
|
||||
template <Unit U = one, Representation Rep = double> using nth_orange = quantity_point_kind<nth_orange_kind, U, Rep>;
|
||||
template<Unit U = one, Representation Rep = double>
|
||||
using apples = quantity_kind<apple, U, Rep>;
|
||||
template<Unit U = one, Representation Rep = double>
|
||||
using oranges = quantity_kind<orange, U, Rep>;
|
||||
template<Unit U = one, Representation Rep = double>
|
||||
using nth_apple = quantity_point_kind<nth_apple_kind, U, Rep>;
|
||||
template<Unit U = one, Representation Rep = double>
|
||||
using nth_orange = quantity_point_kind<nth_orange_kind, U, Rep>;
|
||||
|
||||
/////////////
|
||||
// concepts
|
||||
@@ -137,16 +150,21 @@ static_assert(sizeof(abscissa<metre, double>) == sizeof(double));
|
||||
static_assert(sizeof(ordinate<metre, short>) == sizeof(short));
|
||||
|
||||
template<typename Width, typename Abscissa>
|
||||
concept invalid_types = requires {
|
||||
requires !requires { typename quantity_point_kind<Width, metre, int>; }; // width_kind is not a point kind
|
||||
requires !requires { typename quantity_point_kind<Abscissa, second, int>; }; // unit of a different dimension
|
||||
requires !requires { typename quantity_point_kind<Abscissa, metre, length<metre>>; }; // quantity used as Rep
|
||||
requires !requires { typename quantity_point_kind<Abscissa, metre, quantity_point<dynamic_origin<dim_length>, metre>>; }; // quantity point used as Rep
|
||||
requires !requires { typename quantity_point_kind<Abscissa, metre, width<metre>>; }; // quantity kind used as Rep
|
||||
requires !requires { typename quantity_point_kind<Abscissa, metre, abscissa<metre>>; }; // quantity point kind used as Rep
|
||||
requires !requires { typename quantity_point_kind<metre, Abscissa, double>; }; // reordered arguments
|
||||
requires !requires { typename quantity_point_kind<metre, double, Abscissa>; }; // reordered arguments
|
||||
};
|
||||
concept invalid_types =
|
||||
requires {
|
||||
requires !requires { typename quantity_point_kind<Width, metre, int>; }; // width_kind is not a point kind
|
||||
requires !requires { typename quantity_point_kind<Abscissa, second, int>; }; // unit of a different dimension
|
||||
requires !requires { typename quantity_point_kind<Abscissa, metre, length<metre>>; }; // quantity used as Rep
|
||||
requires !requires {
|
||||
typename quantity_point_kind<Abscissa, metre, quantity_point<dynamic_origin<dim_length>, metre>>;
|
||||
}; // quantity point used as Rep
|
||||
requires !requires { typename quantity_point_kind<Abscissa, metre, width<metre>>; }; // quantity kind used as Rep
|
||||
requires !requires {
|
||||
typename quantity_point_kind<Abscissa, metre, abscissa<metre>>;
|
||||
}; // quantity point kind used as Rep
|
||||
requires !requires { typename quantity_point_kind<metre, Abscissa, double>; }; // reordered arguments
|
||||
requires !requires { typename quantity_point_kind<metre, double, Abscissa>; }; // reordered arguments
|
||||
};
|
||||
static_assert(invalid_types<width_kind, abscissa_kind>);
|
||||
|
||||
static_assert(std::is_trivially_default_constructible_v<abscissa<metre>>);
|
||||
@@ -456,22 +474,23 @@ static_assert([]() {
|
||||
|
||||
template<typename PK, typename U, typename Qx>
|
||||
concept invalid_compound_assignments_ = requires(quantity_point_kind<PK, U, int> x, Qx q) {
|
||||
requires !requires { x += q; };
|
||||
requires !requires { x -= q; };
|
||||
};
|
||||
requires !requires { x += q; };
|
||||
requires !requires { x -= q; };
|
||||
};
|
||||
template<typename Abscissa>
|
||||
concept invalid_compound_assignments = requires(quantity_point_kind<Abscissa, metre, int> x) {
|
||||
requires !requires { x += 1; };
|
||||
requires !requires { x -= 1; };
|
||||
requires invalid_compound_assignments_<Abscissa, metre, length<metre, int>>;
|
||||
requires invalid_compound_assignments_<Abscissa, metre, height<metre, int>>;
|
||||
requires invalid_compound_assignments_<Abscissa, metre, rate_of_climb<metre_per_second, int>>;
|
||||
requires invalid_compound_assignments_<Abscissa, metre, quantity_point<dynamic_origin<dim_length>, metre, int>>;
|
||||
requires invalid_compound_assignments_<Abscissa, metre, std::chrono::seconds>;
|
||||
};
|
||||
concept invalid_compound_assignments =
|
||||
requires(quantity_point_kind<Abscissa, metre, int> x) {
|
||||
requires !requires { x += 1; };
|
||||
requires !requires { x -= 1; };
|
||||
requires invalid_compound_assignments_<Abscissa, metre, length<metre, int>>;
|
||||
requires invalid_compound_assignments_<Abscissa, metre, height<metre, int>>;
|
||||
requires invalid_compound_assignments_<Abscissa, metre, rate_of_climb<metre_per_second, int>>;
|
||||
requires invalid_compound_assignments_<Abscissa, metre, quantity_point<dynamic_origin<dim_length>, metre, int>>;
|
||||
requires invalid_compound_assignments_<Abscissa, metre, std::chrono::seconds>;
|
||||
};
|
||||
static_assert(invalid_compound_assignments<abscissa_kind>);
|
||||
static_assert(invalid_compound_assignments_<time_point_kind, second, std::chrono::seconds>);
|
||||
#if __cpp_lib_chrono >= 201907L
|
||||
#if __cpp_lib_chrono >= 201907L
|
||||
static_assert(invalid_compound_assignments_<time_point_kind, second, std::chrono::sys_seconds>);
|
||||
#endif
|
||||
|
||||
@@ -545,26 +564,26 @@ static_assert(std::equality_comparable_with<abscissa<metre>, abscissa<cgs::centi
|
||||
// clang-format on
|
||||
template<typename Int>
|
||||
concept invalid_equality = requires(quantity_point_kind<abscissa_kind, metre, Int> x, Int i) {
|
||||
requires !requires { x == 1; };
|
||||
requires !requires { x != 1.0; };
|
||||
requires !requires { x == 1 * m; };
|
||||
requires !requires { x != 1.0 * cgs_cm; };
|
||||
requires !requires { x == 1 * km; };
|
||||
requires !requires { x != quantity(1); };
|
||||
requires !requires { x == dimensionless<percent>(1.0); };
|
||||
requires !requires { x != width<metre, int>(1 * m); };
|
||||
requires !requires { x == width<kilometre, double>(1.0 * km); };
|
||||
requires !requires { x != height<metre, int>(1 * m); };
|
||||
requires !requires { x == height<kilometre, double>(1.0 * km); };
|
||||
requires !requires { x == rate_of_climb<kilometre_per_hour, double>(1.0 * (km / h)); };
|
||||
requires !requires { x != quantity_point(1 * m); };
|
||||
requires !requires { x == quantity_point(1.0 * mm); };
|
||||
requires !requires { x != quantity_point(quantity(1)); };
|
||||
requires !requires { x == quantity_point(dimensionless<percent>(1.0)); };
|
||||
requires !requires { x != quantity_point_kind(cgs_width<metre, int>(1 * m)); };
|
||||
requires !requires { x == ordinate<metre, int>(1 * m); };
|
||||
requires !requires { screen_si_width<metre, Int>{} != screen_si_cgs_width<metre, Int>{}; };
|
||||
};
|
||||
requires !requires { x == 1; };
|
||||
requires !requires { x != 1.0; };
|
||||
requires !requires { x == 1 * m; };
|
||||
requires !requires { x != 1.0 * cgs_cm; };
|
||||
requires !requires { x == 1 * km; };
|
||||
requires !requires { x != quantity(1); };
|
||||
requires !requires { x == dimensionless<percent>(1.0); };
|
||||
requires !requires { x != width<metre, int>(1 * m); };
|
||||
requires !requires { x == width<kilometre, double>(1.0 * km); };
|
||||
requires !requires { x != height<metre, int>(1 * m); };
|
||||
requires !requires { x == height<kilometre, double>(1.0 * km); };
|
||||
requires !requires { x == rate_of_climb<kilometre_per_hour, double>(1.0 * (km / h)); };
|
||||
requires !requires { x != quantity_point(1 * m); };
|
||||
requires !requires { x == quantity_point(1.0 * mm); };
|
||||
requires !requires { x != quantity_point(quantity(1)); };
|
||||
requires !requires { x == quantity_point(dimensionless<percent>(1.0)); };
|
||||
requires !requires { x != quantity_point_kind(cgs_width<metre, int>(1 * m)); };
|
||||
requires !requires { x == ordinate<metre, int>(1 * m); };
|
||||
requires !requires { screen_si_width<metre, Int>{} != screen_si_cgs_width<metre, Int>{}; };
|
||||
};
|
||||
static_assert(invalid_equality<int>);
|
||||
|
||||
// clang-format off
|
||||
@@ -580,27 +599,28 @@ static_assert(std::three_way_comparable_with<abscissa<cgs::centimetre, int>, abs
|
||||
static_assert(std::three_way_comparable_with<abscissa<metre>, abscissa<cgs::centimetre>>);
|
||||
// clang-format on
|
||||
template<typename Int>
|
||||
concept invalid_relational = requires(quantity_point_kind<abscissa_kind, metre, Int> x, Int i) {
|
||||
requires !requires { x < 1; };
|
||||
requires !requires { x <= 1.0; };
|
||||
requires !requires { x >= 1 * m; };
|
||||
requires !requires { x > 1.0 * cgs_cm; };
|
||||
requires !requires { x <=> 1 * km; };
|
||||
requires !requires { x < quantity(1); };
|
||||
requires !requires { x <= dimensionless<percent>(1.0); };
|
||||
requires !requires { x >= width<metre, int>(1 * m); };
|
||||
requires !requires { x > width<kilometre, double>(1.0 * km); };
|
||||
requires !requires { x <=> height<metre, int>(1 * m); };
|
||||
requires !requires { x < height<kilometre, double>(1.0 * km); };
|
||||
requires !requires { x <= rate_of_climb<kilometre_per_hour, double>(1.0 * (km / h)); };
|
||||
requires !requires { x >= quantity_point(1 * m); };
|
||||
requires !requires { x > quantity_point(1.0 * mm); };
|
||||
requires !requires { x <=> quantity_point(quantity(1)); };
|
||||
requires !requires { x < quantity_point(dimensionless<percent>(1.0)); };
|
||||
requires !requires { x <= quantity_point_kind(cgs_width<metre, int>(1 * m)); };
|
||||
requires !requires { x >= ordinate<metre, int>(1 * m); };
|
||||
requires !requires { screen_si_width<metre, Int>{} > screen_si_cgs_width<metre, Int>{}; };
|
||||
};
|
||||
concept invalid_relational =
|
||||
requires(quantity_point_kind<abscissa_kind, metre, Int> x, Int i) {
|
||||
requires !requires { x < 1; };
|
||||
requires !requires { x <= 1.0; };
|
||||
requires !requires { x >= 1 * m; };
|
||||
requires !requires { x > 1.0 * cgs_cm; };
|
||||
requires !requires { x <=> 1 * km; };
|
||||
requires !requires { x < quantity(1); };
|
||||
requires !requires { x <= dimensionless<percent>(1.0); };
|
||||
requires !requires { x >= width<metre, int>(1 * m); };
|
||||
requires !requires { x > width<kilometre, double>(1.0 * km); };
|
||||
requires !requires { x <=> height<metre, int>(1 * m); };
|
||||
requires !requires { x < height<kilometre, double>(1.0 * km); };
|
||||
requires !requires { x <= rate_of_climb<kilometre_per_hour, double>(1.0 * (km / h)); };
|
||||
requires !requires { x >= quantity_point(1 * m); };
|
||||
requires !requires { x > quantity_point(1.0 * mm); };
|
||||
requires !requires { x <=> quantity_point(quantity(1)); };
|
||||
requires !requires { x < quantity_point(dimensionless<percent>(1.0)); };
|
||||
requires !requires { x <= quantity_point_kind(cgs_width<metre, int>(1 * m)); };
|
||||
requires !requires { x >= ordinate<metre, int>(1 * m); };
|
||||
requires !requires { screen_si_width<metre, Int>{} > screen_si_cgs_width<metre, Int>{}; };
|
||||
};
|
||||
static_assert(invalid_relational<int>);
|
||||
|
||||
|
||||
@@ -652,25 +672,35 @@ static_assert(same(quantity_point_kind_cast<length<centimetre, int>>(abscissa<cg
|
||||
static_assert(same(quantity_point_kind_cast<screen_si_cgs_width<metre, int>>(screen_si_width<metre, int>(1 * m)), screen_si_cgs_width<metre, int>(1 * m)));
|
||||
// clang-format on
|
||||
template<typename Int>
|
||||
concept invalid_cast = requires(Int i) {
|
||||
requires !requires { quantity_point_kind_cast<apples<one, Int>>(abscissa<metre, Int>(i * m)); };
|
||||
requires !requires { quantity_point_kind_cast<rate_of_climb<metre_per_second, Int>>(abscissa<metre, Int>(i * m)); };
|
||||
requires !requires { quantity_point_kind_cast<apple>(abscissa<metre, Int>(i * m)); };
|
||||
requires !requires { quantity_point_kind_cast<rate_of_climb_kind>(abscissa<metre, Int>(i * m)); };
|
||||
requires !requires { quantity_point_kind_cast<apple, one>(abscissa<metre, Int>(i * m)); };
|
||||
requires !requires { quantity_point_kind_cast<width_kind, metre>(abscissa<metre, Int>(i * m)); };
|
||||
requires !requires { quantity_point_kind_cast<width_kind, kilometre>(abscissa<metre, Int>(i * m)); };
|
||||
requires !requires { quantity_point_kind_cast<height_kind, metre>(abscissa<metre, Int>(i * m)); };
|
||||
requires !requires { quantity_point_kind_cast<height_kind, kilometre>(abscissa<metre, Int>(i * m)); };
|
||||
requires !requires { quantity_point_kind_cast<cgs_width_kind, cgs::centimetre>(abscissa<metre, Int>(i * m)); };
|
||||
requires !requires { quantity_point_kind_cast<rate_of_climb_kind, metre_per_second>(abscissa<metre, Int>(i * m)); };
|
||||
requires !requires { quantity_point_kind_cast<dimensionless<one>>(abscissa<metre, Int>(i * m)); };
|
||||
requires !requires { quantity_point_kind_cast<square_metre>(abscissa<metre, Int>(i * m)); };
|
||||
requires !requires { quantity_point_kind_cast<second>(abscissa<metre, Int>(i * m)); };
|
||||
requires !requires { quantity_point_kind_cast<quantity_point<dynamic_origin<dim_length>, metre, Int>>(abscissa<metre, Int>(i * m)); };
|
||||
requires !requires { quantity_point_kind_cast<quantity_point<dynamic_origin<dim_one>, one, Int>>(abscissa<metre, Int>(i * m)); };
|
||||
requires !requires { quantity_point_kind_cast<quantity_point<dynamic_origin<dim_length>, metre, Int>>(screen_si_width<metre, Int>(i * m)); };
|
||||
};
|
||||
concept invalid_cast =
|
||||
requires(Int i) {
|
||||
requires !requires { quantity_point_kind_cast<apples<one, Int>>(abscissa<metre, Int>(i * m)); };
|
||||
requires !requires { quantity_point_kind_cast<rate_of_climb<metre_per_second, Int>>(abscissa<metre, Int>(i * m)); };
|
||||
requires !requires { quantity_point_kind_cast<apple>(abscissa<metre, Int>(i * m)); };
|
||||
requires !requires { quantity_point_kind_cast<rate_of_climb_kind>(abscissa<metre, Int>(i * m)); };
|
||||
requires !requires { quantity_point_kind_cast<apple, one>(abscissa<metre, Int>(i * m)); };
|
||||
requires !requires { quantity_point_kind_cast<width_kind, metre>(abscissa<metre, Int>(i * m)); };
|
||||
requires !requires { quantity_point_kind_cast<width_kind, kilometre>(abscissa<metre, Int>(i * m)); };
|
||||
requires !requires { quantity_point_kind_cast<height_kind, metre>(abscissa<metre, Int>(i * m)); };
|
||||
requires !requires { quantity_point_kind_cast<height_kind, kilometre>(abscissa<metre, Int>(i * m)); };
|
||||
requires !requires { quantity_point_kind_cast<cgs_width_kind, cgs::centimetre>(abscissa<metre, Int>(i * m)); };
|
||||
requires !requires { quantity_point_kind_cast<rate_of_climb_kind, metre_per_second>(abscissa<metre, Int>(i * m)); };
|
||||
requires !requires { quantity_point_kind_cast<dimensionless<one>>(abscissa<metre, Int>(i * m)); };
|
||||
requires !requires { quantity_point_kind_cast<square_metre>(abscissa<metre, Int>(i * m)); };
|
||||
requires !requires { quantity_point_kind_cast<second>(abscissa<metre, Int>(i * m)); };
|
||||
requires !requires {
|
||||
quantity_point_kind_cast<quantity_point<dynamic_origin<dim_length>, metre, Int>>(
|
||||
abscissa<metre, Int>(i * m));
|
||||
};
|
||||
requires !requires {
|
||||
quantity_point_kind_cast<quantity_point<dynamic_origin<dim_one>, one, Int>>(
|
||||
abscissa<metre, Int>(i * m));
|
||||
};
|
||||
requires !requires {
|
||||
quantity_point_kind_cast<quantity_point<dynamic_origin<dim_length>, metre, Int>>(
|
||||
screen_si_width<metre, Int>(i * m));
|
||||
};
|
||||
};
|
||||
static_assert(invalid_cast<int>);
|
||||
|
||||
|
||||
@@ -687,16 +717,16 @@ struct ordinate_kind : point_kind<ordinate_kind, height_kind> {};
|
||||
|
||||
struct point {};
|
||||
|
||||
template <units::QuantityPointKindOf<abscissa_kind> Abscissa, units::QuantityPointKindOf<ordinate_kind> Ordinate>
|
||||
template<units::QuantityPointKindOf<abscissa_kind> Abscissa, units::QuantityPointKindOf<ordinate_kind> Ordinate>
|
||||
point operator+(Abscissa, Ordinate);
|
||||
|
||||
} // namespace mylib
|
||||
|
||||
namespace yourapp {
|
||||
|
||||
static_assert(is_same_v<mylib::point,
|
||||
decltype(quantity_point_kind(quantity_kind<mylib::width_kind, metre, int>(1 * m)) +
|
||||
quantity_point_kind(quantity_kind<mylib::height_kind, metre, int>(1 * m)))>);
|
||||
static_assert(
|
||||
is_same_v<mylib::point, decltype(quantity_point_kind(quantity_kind<mylib::width_kind, metre, int>(1 * m)) +
|
||||
quantity_point_kind(quantity_kind<mylib::height_kind, metre, int>(1 * m)))>);
|
||||
|
||||
} // namespace yourapp
|
||||
|
||||
|
||||
@@ -34,24 +34,27 @@ template<typename T>
|
||||
inline constexpr bool compare_impl<T, T> = true;
|
||||
|
||||
template<typename T, typename U>
|
||||
requires (UNITS_DOWNCAST_MODE == 0)
|
||||
requires(UNITS_DOWNCAST_MODE == 0)
|
||||
inline constexpr bool compare_impl<T, U> = units::equivalent<T, U>;
|
||||
|
||||
template<typename T, typename U>
|
||||
inline constexpr bool compare = compare_impl<std::remove_cvref_t<T>, std::remove_cvref_t<U>>;
|
||||
|
||||
template<typename T, typename... Us, typename... Vs>
|
||||
constexpr bool constructible_from(Vs...) {
|
||||
constexpr bool constructible_from(Vs...)
|
||||
{
|
||||
return std::constructible_from<T, Us..., Vs...>;
|
||||
}
|
||||
|
||||
template<class T> void convertible_from__(T);
|
||||
template<class T>
|
||||
void convertible_from__(T);
|
||||
|
||||
template<typename T, typename... Us>
|
||||
concept convertible_from_ = requires(Us... us) { convertible_from__<T>({us...}); };
|
||||
|
||||
template<typename T, typename... Us, typename... Vs>
|
||||
constexpr bool convertible_from(Vs...) {
|
||||
constexpr bool convertible_from(Vs...)
|
||||
{
|
||||
if constexpr (sizeof...(Us) + sizeof...(Vs) == 1)
|
||||
return std::is_convertible_v<Us..., Vs..., T>;
|
||||
else
|
||||
@@ -59,24 +62,28 @@ constexpr bool convertible_from(Vs...) {
|
||||
}
|
||||
|
||||
template<typename T, typename... Us, typename... Vs>
|
||||
constexpr bool constructible_or_convertible_from(Vs...) {
|
||||
constexpr bool constructible_or_convertible_from(Vs...)
|
||||
{
|
||||
return constructible_from<T, Us..., Vs...>() || convertible_from<T, Us..., Vs...>();
|
||||
}
|
||||
|
||||
template<typename T, typename... Us, typename... Vs>
|
||||
constexpr bool constructible_and_convertible_from(Vs...) {
|
||||
constexpr bool constructible_and_convertible_from(Vs...)
|
||||
{
|
||||
return constructible_from<T, Us..., Vs...>() && convertible_from<T, Us..., Vs...>();
|
||||
}
|
||||
|
||||
template<typename T, typename... Us>
|
||||
requires (constructible_from<T, Us...>())
|
||||
constexpr T construct_from(Us... us) {
|
||||
requires(constructible_from<T, Us...>())
|
||||
constexpr T construct_from(Us... us)
|
||||
{
|
||||
return T(us...);
|
||||
}
|
||||
|
||||
template<typename T, typename... Us>
|
||||
requires (convertible_from<T, Us...>())
|
||||
constexpr T convert_from(Us... us) {
|
||||
requires(convertible_from<T, Us...>())
|
||||
constexpr T convert_from(Us... us)
|
||||
{
|
||||
if constexpr (sizeof...(Us) == 1)
|
||||
return [](T t) { return t; }(us...);
|
||||
else
|
||||
@@ -84,16 +91,18 @@ constexpr T convert_from(Us... us) {
|
||||
}
|
||||
|
||||
template<std::equality_comparable T, typename... Us>
|
||||
requires (constructible_from<T, Us...>() && convertible_from<T, Us...>())
|
||||
constexpr T construct_and_convert_from(Us... us) {
|
||||
requires(constructible_from<T, Us...>() && convertible_from<T, Us...>())
|
||||
constexpr T construct_and_convert_from(Us... us)
|
||||
{
|
||||
T t{construct_from<T>(us...)};
|
||||
assert(t == convert_from<T>(us...));
|
||||
return t;
|
||||
}
|
||||
|
||||
template<typename T, typename... Us>
|
||||
requires (constructible_from<T, Us...>() && !convertible_from<T, Us...>())
|
||||
constexpr T construct_from_only(Us... us) {
|
||||
requires(constructible_from<T, Us...>() && !convertible_from<T, Us...>())
|
||||
constexpr T construct_from_only(Us... us)
|
||||
{
|
||||
return construct_from<T>(us...);
|
||||
}
|
||||
|
||||
@@ -109,7 +118,8 @@ inline constexpr bool ctad_constructible_from_<T, std::void_t<decltype(T(Us{}...
|
||||
#endif
|
||||
|
||||
template<template<typename...> typename T, typename... Us, typename... Vs>
|
||||
constexpr bool ctad_constructible_from(Vs...) {
|
||||
constexpr bool ctad_constructible_from(Vs...)
|
||||
{
|
||||
return ctad_constructible_from_<T, void, Us..., Vs...>;
|
||||
}
|
||||
|
||||
@@ -118,8 +128,10 @@ constexpr auto same = []<std::equality_comparable T>(T l, T r) { return l == r;
|
||||
#else
|
||||
constexpr auto same = []<typename T, typename U>(T l, U r)
|
||||
requires requires { l == r; }
|
||||
// requires std::equality_comparable_with<T, U> // TODO: Fix #205
|
||||
{ return l == r; };
|
||||
// requires std::equality_comparable_with<T, U> // TODO: Fix #205
|
||||
{
|
||||
return l == r;
|
||||
};
|
||||
#endif
|
||||
|
||||
template<auto F>
|
||||
|
||||
Reference in new issue
Block a user