Skip to content

Commit

Permalink
Merge branch 'master-msvc-194' into master-msvc-194-only-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
czjhoppe committed Sep 4, 2024
2 parents af077ef + 8be458b commit 3174291
Show file tree
Hide file tree
Showing 17 changed files with 145 additions and 163 deletions.
2 changes: 1 addition & 1 deletion example/measurement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void example()
const auto acceleration = isq::acceleration(measurement{9.8, 0.1} * m / s2);
const auto time = measurement{1.2, 0.1} * s;

const MP_UNITS_CONSTRAINED_AUTO_WORKAROUND(QuantityOf<isq::velocity>) auto velocity = acceleration * time;
const QuantityOf<(isq::velocity)> auto velocity = acceleration * time;
std::cout << acceleration << " * " << time << " = " << velocity << " = " << velocity.in(km / h) << '\n';

const auto length = measurement{123., 1.} * m;
Expand Down
11 changes: 3 additions & 8 deletions src/core/include/mp-units/bits/fmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,8 @@ constexpr void handle_dynamic_spec(int& value, fmt_arg_ref<typename Context::cha
}
}

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4702)
#endif
MP_UNITS_DIAGNOSTIC_PUSH
MP_UNITS_DIAGNOSTIC_IGNORE_UNREACHABLE
struct width_checker {
template<typename T>
[[nodiscard]] constexpr unsigned long long operator()(T value) const
Expand All @@ -205,10 +203,7 @@ struct width_checker {
MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("width is not integer"));
}
};

#ifdef _MSC_VER
#pragma warning(pop)
#endif
MP_UNITS_DIAGNOSTIC_POP

MP_UNITS_EXPORT_END

Expand Down
4 changes: 2 additions & 2 deletions src/core/include/mp-units/bits/get_associated_quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ template<AssociatedUnit U>
template<AssociatedUnit U>
[[nodiscard]] consteval auto get_associated_quantity(U u)
{
constexpr bool all_kinds = all_are_kinds(MP_UNITS_IS_CONST_EXPR(u));
constexpr bool all_kinds = all_are_kinds(MP_UNITS_IS_CONST_EXPR_WORKAROUND(u));
if constexpr (all_kinds)
return kind_of<get_associated_quantity_impl(MP_UNITS_IS_CONST_EXPR(u))>;
return kind_of<get_associated_quantity_impl(MP_UNITS_IS_CONST_EXPR_WORKAROUND(u))>;
else
return get_associated_quantity_impl(u);
}
Expand Down
27 changes: 7 additions & 20 deletions src/core/include/mp-units/bits/hacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,6 @@
#if !defined MP_UNITS_HOSTED && defined __STDC_HOSTED__
#define MP_UNITS_HOSTED __STDC_HOSTED__
#endif

#if MP_UNITS_COMP_MSVC

#define MP_UNITS_TYPENAME typename
#define MP_UNITS_EXPRESSION(x) (x)
#define MP_UNITS_IS_VALUE(x) (x)
#define MP_UNITS_IS_CONST_EXPR(x) \
decltype(x) {}

#else

#define MP_UNITS_TYPENAME
#define MP_UNITS_EXPRESSION(x) x
#define MP_UNITS_IS_VALUE(x) x
#define MP_UNITS_IS_CONST_EXPR(x) x

#endif

#if MP_UNITS_COMP_GCC

#define MP_UNITS_REMOVE_CONST(expr) std::remove_const_t<expr>
Expand Down Expand Up @@ -129,13 +111,18 @@ inline constexpr from_range_t from_range{};

#if MP_UNITS_COMP_MSVC

#define MP_UNITS_CONSTRAINED_AUTO_WORKAROUND(X)
#define MP_UNITS_CONSTRAINED_NTTP_WORKAROUND(X)
#define MP_UNITS_EXPRESSION_WORKAROUND(x) (x)
#define MP_UNITS_IS_VALUE_WORKAROUND(x) (x)
#define MP_UNITS_IS_CONST_EXPR_WORKAROUND(x) \
decltype(x) {}

#else

#define MP_UNITS_CONSTRAINED_AUTO_WORKAROUND(X) X
#define MP_UNITS_CONSTRAINED_NTTP_WORKAROUND(X) X
#define MP_UNITS_EXPRESSION_WORKAROUND(x) x
#define MP_UNITS_IS_VALUE_WORKAROUND(x) x
#define MP_UNITS_IS_CONST_EXPR_WORKAROUND(x) x

#endif

Expand Down
8 changes: 4 additions & 4 deletions src/core/include/mp-units/bits/sudo_cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ template<typename T, typename Other>
struct get_common_type : std::common_type<T, Other> {};

template<typename T, typename Other>
using maybe_common_type = MP_UNITS_TYPENAME
using maybe_common_type =
std::conditional_t<has_common_type_v<T, Other>, get_common_type<T, Other>, std::type_identity<T>>::type;

/**
Expand Down Expand Up @@ -108,20 +108,20 @@ template<Quantity To, typename From>
constexpr auto q_unit = std::remove_reference_t<From>::unit;
if constexpr (q_unit == To::unit) {
// no scaling of the number needed
return {static_cast<MP_UNITS_TYPENAME To::rep>(std::forward<From>(q).numerical_value_is_an_implementation_detail_),
return {static_cast< To::rep>(std::forward<From>(q).numerical_value_is_an_implementation_detail_),
To::reference}; // this is the only (and recommended) way to do a truncating conversion on a number, so we
// are using static_cast to suppress all the compiler warnings on conversions
} else {
// scale the number
using traits = magnitude_conversion_traits<To, std::remove_reference_t<From>>;
if constexpr (std::is_floating_point_v<typename traits::multiplier_type>) {
// this results in great assembly
auto res = static_cast<MP_UNITS_TYPENAME To::rep>(
auto res = static_cast< To::rep>(
static_cast<traits::c_type>(q.numerical_value_is_an_implementation_detail_) * traits::ratio);
return {res, To::reference};
} else {
// this is slower but allows conversions like 2000 m -> 2 km without loosing data
auto res = static_cast<MP_UNITS_TYPENAME To::rep>(
auto res = static_cast< To::rep>(
static_cast<traits::c_type>(q.numerical_value_is_an_implementation_detail_) * traits::num_mult /
traits::den_mult * traits::irr_mult);
return {res, To::reference};
Expand Down
26 changes: 13 additions & 13 deletions src/core/include/mp-units/bits/type_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ struct type_list_map_impl<From<Args...>, To> {
};

template<TypeList From, template<typename...> typename To>
using type_list_map = MP_UNITS_TYPENAME type_list_map_impl<From, To>::type;
using type_list_map = type_list_map_impl<From, To>::type;


// element
Expand Down Expand Up @@ -105,7 +105,7 @@ struct type_list_front_impl<List<T, Ts...>> {
};

template<TypeList List>
using type_list_front = MP_UNITS_TYPENAME type_list_front_impl<List>::type;
using type_list_front = type_list_front_impl<List>::type;

// back
template<TypeList List>
Expand All @@ -121,7 +121,7 @@ struct type_list_push_front_impl<List<OldTypes...>, NewTypes...> {
};

template<TypeList List, typename... Types>
using type_list_push_front = MP_UNITS_TYPENAME type_list_push_front_impl<List, Types...>::type;
using type_list_push_front = type_list_push_front_impl<List, Types...>::type;

// push_back
template<typename List, typename... Types>
Expand All @@ -133,7 +133,7 @@ struct type_list_push_back_impl<List<OldTypes...>, NewTypes...> {
};

template<TypeList List, typename... Types>
using type_list_push_back = MP_UNITS_TYPENAME type_list_push_back_impl<List, Types...>::type;
using type_list_push_back = type_list_push_back_impl<List, Types...>::type;

// join
template<typename List, typename... Rest>
Expand All @@ -143,11 +143,11 @@ struct type_list_join_impl {

template<template<typename...> typename List, typename... First, typename... Second, typename... Rest>
struct type_list_join_impl<List<First...>, List<Second...>, Rest...> {
using type = MP_UNITS_TYPENAME type_list_join_impl<List<First..., Second...>, Rest...>::type;
using type = type_list_join_impl<List<First..., Second...>, Rest...>::type;
};

template<TypeList... Lists>
using type_list_join = MP_UNITS_TYPENAME type_list_join_impl<Lists...>::type;
using type_list_join = type_list_join_impl<Lists...>::type;

// split
template<typename List, typename First, typename Second>
Expand Down Expand Up @@ -195,19 +195,19 @@ template<template<typename...> typename List, typename Lhs1, typename... LhsRest
template<typename, typename> typename Pred>
requires Pred<Lhs1, Rhs1>::value
struct type_list_merge_sorted_impl<List<Lhs1, LhsRest...>, List<Rhs1, RhsRest...>, Pred> {
using type = MP_UNITS_TYPENAME type_list_push_front_impl<
using type = type_list_push_front_impl<
typename type_list_merge_sorted_impl<List<LhsRest...>, List<Rhs1, RhsRest...>, Pred>::type, Lhs1>::type;
};

template<template<typename...> typename List, typename Lhs1, typename... LhsRest, typename Rhs1, typename... RhsRest,
template<typename, typename> typename Pred>
struct type_list_merge_sorted_impl<List<Lhs1, LhsRest...>, List<Rhs1, RhsRest...>, Pred> {
using type = MP_UNITS_TYPENAME type_list_push_front_impl<
using type = type_list_push_front_impl<
typename type_list_merge_sorted_impl<List<Lhs1, LhsRest...>, List<RhsRest...>, Pred>::type, Rhs1>::type;
};

template<TypeList SortedList1, TypeList SortedList2, template<typename, typename> typename Pred>
using type_list_merge_sorted = MP_UNITS_TYPENAME type_list_merge_sorted_impl<SortedList1, SortedList2, Pred>::type;
using type_list_merge_sorted = type_list_merge_sorted_impl<SortedList1, SortedList2, Pred>::type;

// sort
template<typename List, template<typename, typename> typename Pred>
Expand All @@ -227,13 +227,13 @@ template<template<typename...> typename List, typename... Types, template<typena
struct type_list_sort_impl<List<Types...>, Pred> {
using types = List<Types...>;
using split = type_list_split_half<List<Types...>>;
using sorted_left = MP_UNITS_TYPENAME type_list_sort_impl<typename split::first_list, Pred>::type;
using sorted_right = MP_UNITS_TYPENAME type_list_sort_impl<typename split::second_list, Pred>::type;
using type = MP_UNITS_TYPENAME type_list_merge_sorted_impl<sorted_left, sorted_right, Pred>::type;
using sorted_left = type_list_sort_impl<typename split::first_list, Pred>::type;
using sorted_right = type_list_sort_impl<typename split::second_list, Pred>::type;
using type = type_list_merge_sorted_impl<sorted_left, sorted_right, Pred>::type;
};

template<TypeList List, template<typename, typename> typename Pred>
using type_list_sort = MP_UNITS_TYPENAME type_list_sort_impl<List, Pred>::type;
using type_list_sort = type_list_sort_impl<List, Pred>::type;

} // namespace mp_units::detail

Expand Down
12 changes: 6 additions & 6 deletions src/core/include/mp-units/ext/type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct conditional_impl<true> {
MP_UNITS_EXPORT_BEGIN

template<bool B, typename T, typename F>
using conditional = MP_UNITS_TYPENAME detail::conditional_impl<B>::template type<T, F>;
using conditional = detail::conditional_impl<B>::template type<T, F>;

// is_same
template<class T, class U>
Expand Down Expand Up @@ -99,7 +99,7 @@ namespace detail {

template<typename T>
struct get_value_type {
using type = MP_UNITS_TYPENAME T::value_type;
using type = T::value_type;
};

template<typename T>
Expand All @@ -112,13 +112,13 @@ struct get_element_type {
template<typename T>
requires requires { typename T::value_type; } || requires { typename T::element_type; }
struct wrapped_type {
using type = MP_UNITS_TYPENAME
using type =
conditional<requires { typename T::value_type; }, detail::get_value_type<T>, detail::get_element_type<T>>::type;
};

template<typename T>
requires requires { typename T::value_type; } || requires { typename T::element_type; }
using wrapped_type_t = MP_UNITS_TYPENAME wrapped_type<T>::type;
using wrapped_type_t = wrapped_type<T>::type;

template<typename T>
struct value_type {
Expand All @@ -128,11 +128,11 @@ struct value_type {
template<typename T>
requires requires { typename wrapped_type_t<T>; }
struct value_type<T> {
using type = MP_UNITS_TYPENAME wrapped_type_t<T>;
using type = wrapped_type_t<T>;
};

template<typename T>
using value_type_t = MP_UNITS_TYPENAME value_type<T>::type;
using value_type_t = value_type<T>::type;

template<typename T, typename... Ts>
concept one_of = (false || ... || std::same_as<T, Ts>);
Expand Down
4 changes: 2 additions & 2 deletions src/core/include/mp-units/framework/construction_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ template<Reference R>
struct delta_ {
template<typename Rep>
requires RepresentationOf<std::remove_cvref_t<Rep>, get_quantity_spec(R{}).character>
[[nodiscard]] constexpr quantity<MP_UNITS_EXPRESSION(R{}), std::remove_cvref_t<Rep>> operator()(Rep&& lhs) const
[[nodiscard]] constexpr quantity< MP_UNITS_EXPRESSION_WORKAROUND(R{}), std::remove_cvref_t<Rep>> operator()(Rep&& lhs) const
{
return quantity{std::forward<Rep>(lhs), R{}};
}
Expand All @@ -51,7 +51,7 @@ template<Reference R>
struct absolute_ {
template<typename Rep>
requires RepresentationOf<std::remove_cvref_t<Rep>, get_quantity_spec(R{}).character>
[[nodiscard]] constexpr quantity_point<MP_UNITS_EXPRESSION(R{}), default_point_origin(R{}), std::remove_cvref_t<Rep>>
[[nodiscard]] constexpr quantity_point< MP_UNITS_EXPRESSION_WORKAROUND(R{}), default_point_origin(R{}), std::remove_cvref_t<Rep>>
operator()(Rep&& lhs) const
{
return quantity_point{quantity{std::forward<Rep>(lhs), R{}}};
Expand Down
10 changes: 5 additions & 5 deletions src/core/include/mp-units/framework/expression_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ struct expr_type_impl<power<T, Ints...>> : std::type_identity<T> {};
} // namespace detail

template<typename T>
using expr_type = MP_UNITS_TYPENAME detail::expr_type_impl<T>::type;
using expr_type = detail::expr_type_impl<T>::type;

namespace detail {

Expand Down Expand Up @@ -182,25 +182,25 @@ struct expr_consolidate_impl<type_list<T, Rest...>> {
template<typename T, typename... Rest>
requires(!is_specialization_of_power<T>)
struct expr_consolidate_impl<type_list<T, T, Rest...>> {
using type = MP_UNITS_TYPENAME expr_consolidate_impl<type_list<power<T, 2>, Rest...>>::type;
using type = expr_consolidate_impl<type_list<power<T, 2>, Rest...>>::type;
};

// replaces the instance of a type and a power of it with one with incremented power
template<typename T, int... Ints, typename... Rest>
struct expr_consolidate_impl<type_list<T, power<T, Ints...>, Rest...>> {
using type =
MP_UNITS_TYPENAME expr_consolidate_impl<type_list<power_or_T<T, power<T, Ints...>::exponent + 1>, Rest...>>::type;
expr_consolidate_impl<type_list<power_or_T<T, power<T, Ints...>::exponent + 1>, Rest...>>::type;
};

// accumulates the powers of instances of the same type (removes the element in case the accumulation result is `0`)
template<typename T, int... Ints1, int... Ints2, typename... Rest>
struct expr_consolidate_impl<type_list<power<T, Ints1...>, power<T, Ints2...>, Rest...>> {
static constexpr ratio r = power<T, Ints1...>::exponent + power<T, Ints2...>::exponent;
using type = MP_UNITS_TYPENAME expr_consolidate_impl<type_list<power_or_T<T, r>, Rest...>>::type;
using type = expr_consolidate_impl<type_list<power_or_T<T, r>, Rest...>>::type;
};

template<typename List>
using expr_consolidate = MP_UNITS_TYPENAME expr_consolidate_impl<List>::type;
using expr_consolidate = expr_consolidate_impl<List>::type;


/**
Expand Down
4 changes: 2 additions & 2 deletions src/core/include/mp-units/framework/quantity_point.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ template<PointOrigin PO>
struct point_origin_interface {
template<PointOrigin PO, Quantity Q>
requires ReferenceOf<std::remove_const_t<decltype(Q::reference)>, PO::quantity_spec>
[[nodiscard]] friend constexpr quantity_point<Q::reference, MP_UNITS_EXPRESSION(PO{}), typename Q::rep> operator+(
[[nodiscard]] friend constexpr quantity_point<Q::reference, MP_UNITS_EXPRESSION_WORKAROUND(PO{}), typename Q::rep> operator+(
PO, Q&& q)
{
return quantity_point{std::forward<Q>(q), PO{}};
}

template<Quantity Q, PointOrigin PO>
requires ReferenceOf<std::remove_const_t<decltype(Q::reference)>, PO::quantity_spec>
[[nodiscard]] friend constexpr quantity_point<Q::reference, MP_UNITS_EXPRESSION(PO{}), typename Q::rep> operator+(
[[nodiscard]] friend constexpr quantity_point<Q::reference, MP_UNITS_EXPRESSION_WORKAROUND(PO{}), typename Q::rep> operator+(
Q&& q, PO po)
{
return po + std::forward<Q>(q);
Expand Down
Loading

0 comments on commit 3174291

Please sign in to comment.