Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[msvc] changes to make library compatible with msvc compiler (194) #607

Merged
merged 48 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
72e03f4
[msvc][fix] msvc needs explicit namespace for some using-declarations
czjhoppe Aug 30, 2024
33837c5
[msvc][fix] some short names hide global identifier
czjhoppe Aug 30, 2024
aa26488
[msvc][fix] msvc compiler has different behaviour for *= and * at com…
czjhoppe Aug 30, 2024
5d3ed20
[msvc][fix] some short names hide global identifier
czjhoppe Aug 30, 2024
30ac288
[msvc][fix] a lot of brackets where msvc prefers
czjhoppe Aug 30, 2024
d491758
[msvc][fix] return type of chrono_literal "s" is not defined. Is doub…
czjhoppe Aug 30, 2024
e9ad43a
[msvc][fix] CTAD for quantity_point does not work.
czjhoppe Aug 30, 2024
1913fbe
[msvc][cmake] disable linear_algebra_test.cpp tests because of errors…
czjhoppe Aug 30, 2024
482150e
[msvc][fix] some more errros in examples
czjhoppe Aug 30, 2024
19e358e
[mscv][fix] string_view iterator is not castalbe to char
czjhoppe Aug 30, 2024
464c555
[msvc][fix] resolve ambigious call to find_first_of
czjhoppe Aug 30, 2024
5e657ba
[msvc][fix] msvc complains about requires expression (no common type …
czjhoppe Aug 30, 2024
3d32d5d
[msvc][fix] internal compiler error for requires expression. "simplif…
czjhoppe Aug 30, 2024
924782f
[mscv][fix] weird problem with PO in quantity_point.h. replace with p…
czjhoppe Aug 30, 2024
cea5d70
[msvc][fix] disable C4702 unreachable code
czjhoppe Aug 30, 2024
3a6fc90
[msvc][fix] compiler does not get that expression can be evalutated t…
czjhoppe Aug 30, 2024
918a8b7
[msvc][fix] parse error in refernce.h. resolved with more brackets.
czjhoppe Aug 30, 2024
4b61716
:boom: [msvc][conan] enable msvc with version 194.
czjhoppe Aug 30, 2024
4d71573
[msvc][fix] update changes for master
czjhoppe Sep 3, 2024
e258009
[msvc][fmt] diable warning in smalest scope
czjhoppe Sep 3, 2024
5ae1304
[hacks] add MP_UNITS_EXPRESSION
czjhoppe Sep 3, 2024
a89bfc6
[hacks] add MP_UNITS_IS_VALUE
czjhoppe Sep 3, 2024
48c4f29
[hacks] add MP_UNITS_IS_CONST_EXPR(from)
czjhoppe Sep 3, 2024
b5c9dca
[naming] change some more names
czjhoppe Sep 3, 2024
0b0d334
[clang-format]
czjhoppe Sep 3, 2024
61ada08
[msvc][conan] update test_package.cpp
czjhoppe Sep 3, 2024
af077ef
[msvc][fix] revert changes in example and test folder
czjhoppe Sep 3, 2024
d1897b1
[PR] change disable error to macro
czjhoppe Sep 4, 2024
d18bb28
[PR] remove MP_UNITS_TYPENAME
czjhoppe Sep 4, 2024
712afc3
[PR] rename macros to match naming conventions for workaround
czjhoppe Sep 4, 2024
b05b379
[PR] move is_mp_units_stream to detail and change from concept to con…
czjhoppe Sep 4, 2024
8be458b
[msvc] remove MP_UNITS_CONSTRAINED_AUTO_WORKAROUND
czjhoppe Sep 4, 2024
3174291
Merge branch 'master-msvc-194' into master-msvc-194-only-lib
czjhoppe Sep 4, 2024
93af5db
[clang-format]
czjhoppe Sep 4, 2024
e3034c5
Merge branch 'master-msvc-194-only-lib' into master-msvc-194
czjhoppe Sep 9, 2024
1d0dbf4
Merge remote-tracking branch 'mpusz/master' into master-msvc-194
czjhoppe Sep 9, 2024
aebf55c
Revert "Merge branch 'master-msvc-194-only-lib' into master-msvc-194"
czjhoppe Sep 9, 2024
9ce76ed
[msvc][fix] remvoe MP_UNITS_IS_CONST_EXPR_WORKAROUND in constexpr bra…
czjhoppe Sep 9, 2024
eaed061
[msvc][fix][unit.h] move requires before function signature instead o…
czjhoppe Sep 9, 2024
5254467
[msvc][fix] add Workaround Macro to conan test-package
czjhoppe Sep 9, 2024
3da6db7
[msvc][fix] remove all unnecessary MP_UNITS_IS_CONST_EXPR_WORKAROUND
czjhoppe Sep 9, 2024
ee4a706
[msvc][fix] remove MP_UNITS_IS_CONST_EXPR_WORKAROUND
czjhoppe Sep 10, 2024
f651438
[clang-format]
czjhoppe Sep 10, 2024
413966e
[msvc][fix] revert changes in example and test folder
czjhoppe Sep 10, 2024
0532f41
Merge branch 'master' into master-msvc-194-only-lib
czjhoppe Sep 10, 2024
4f4da58
[msvc][fix] remove MP_UNITS_CONSTRAINED_AUTO_WORKAROUND in example
czjhoppe Sep 10, 2024
5ecb6c2
[msvc][fix] add Todo comment for bug
czjhoppe Sep 10, 2024
329b17e
clang-format
czjhoppe Sep 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _feature_compatibility(self):
"gcc": "12",
"clang": "16",
"apple-clang": "15",
"msvc": "",
"msvc": "194",
},
},
"std_format": {
Expand Down
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
6 changes: 3 additions & 3 deletions src/core/include/mp-units/bits/fmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ constexpr void handle_dynamic_spec(int& value, fmt_arg_ref<typename Context::cha
}
}

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 @@ -199,9 +201,9 @@ struct width_checker {
return static_cast<unsigned long long>(value);
}
MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("width is not integer"));
return 0;
}
};
MP_UNITS_DIAGNOSTIC_POP

MP_UNITS_EXPORT_END

Expand Down Expand Up @@ -253,7 +255,6 @@ template<typename Char, typename Handler>
if (c == '%') return begin; // mp-units extension
if (!::mp_units::detail::is_name_start(c)) {
MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("invalid format string"));
return begin;
}
auto it = begin;
do {
Expand Down Expand Up @@ -372,7 +373,6 @@ template<typename Char, typename Specs>
if (c == '}') return begin;
if (c == '{') {
MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("invalid fill character '{'"));
return begin;
}
specs.fill = {begin, to_unsigned(p - begin)};
begin = p + 1;
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(u);
constexpr bool all_kinds = all_are_kinds(U{});
if constexpr (all_kinds)
return kind_of<get_associated_quantity_impl(u)>;
return kind_of<get_associated_quantity_impl(U{})>;
else
return get_associated_quantity_impl(u);
}
Expand Down
16 changes: 4 additions & 12 deletions src/core/include/mp-units/bits/hacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,6 @@
// workarounds for https://cplusplus.github.io/CWG/issues/2387.html
#define MP_UNITS_INLINE inline

#if MP_UNITS_COMP_MSVC

#define MP_UNITS_TYPENAME typename

#else

#define MP_UNITS_TYPENAME

#endif

#if MP_UNITS_COMP_GCC

#define MP_UNITS_REMOVE_CONST(expr) std::remove_const_t<expr>
Expand Down Expand Up @@ -125,13 +115,15 @@ 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)

#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

#endif

Expand Down
16 changes: 14 additions & 2 deletions src/core/include/mp-units/bits/sudo_cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,21 @@

namespace mp_units::detail {

template<typename AlwaysVoid, typename... Ts>
struct has_common_type_impl : std::false_type {};

template<typename... Ts>
struct has_common_type_impl<std::void_t<std::common_type_t<Ts...>>, Ts...> : std::true_type {};

template<typename... Ts>
using has_common_type = typename has_common_type_impl<void, Ts...>::type;

template<typename... Ts>
constexpr bool has_common_type_v = has_common_type_impl<void, Ts...>::value;

mpusz marked this conversation as resolved.
Show resolved Hide resolved
template<typename T, typename Other>
using maybe_common_type = std::conditional_t<requires { typename std::common_type_t<T, Other>; },
std::common_type<T, Other>, std::type_identity<T>>::type;
using maybe_common_type =
std::conditional_t<has_common_type_v<T, Other>, std::common_type<T, Other>, std::type_identity<T>>::type;

/**
* @brief Type-related details about the conversion from one quantity to another
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 @@ -98,7 +98,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 @@ -111,13 +111,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 @@ -127,11 +127,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
6 changes: 3 additions & 3 deletions src/core/include/mp-units/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ namespace mp_units::detail {
template<typename Char>
[[nodiscard]] constexpr const Char* at_most_one_of(const Char* begin, const Char* end, std::string_view modifiers)
{
const Char* const it = find_first_of(begin, end, modifiers.begin(), modifiers.end());
if (it != end && find_first_of(it + 1, end, modifiers.begin(), modifiers.end()) != end)
const Char* const it = mp_units::detail::find_first_of(begin, end, modifiers.begin(), modifiers.end());
if (it != end && mp_units::detail::find_first_of(it + 1, end, modifiers.begin(), modifiers.end()) != end)
throw MP_UNITS_STD_FMT::format_error("only one of '" + std::string(modifiers) +
"' unit modifiers may be used in the format spec");
return it;
Expand Down Expand Up @@ -452,7 +452,7 @@ class MP_UNITS_STD_FMT::formatter<mp_units::quantity<Reference, Rep>, Char> {
}
// user provided format
quantity_formatter f{*this, out, q, locale};
parse_quantity_specs(modifiers_format_str_.begin(), modifiers_format_str_.end(), f);
parse_quantity_specs(modifiers_format_str_.data(), modifiers_format_str_.data() + modifiers_format_str_.size(), f);
mpusz marked this conversation as resolved.
Show resolved Hide resolved
return f.out;
}

Expand Down
5 changes: 3 additions & 2 deletions src/core/include/mp-units/framework/construction_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace mp_units {
template<Reference R>
struct delta_ {
template<typename FwdRep, RepresentationOf<get_quantity_spec(R{}).character> Rep = std::remove_cvref_t<FwdRep>>
[[nodiscard]] constexpr quantity<R{}, Rep> operator()(FwdRep&& lhs) const
[[nodiscard]] constexpr quantity<MP_UNITS_EXPRESSION_WORKAROUND(R{}), Rep> operator()(FwdRep&& lhs) const
{
return quantity{std::forward<FwdRep>(lhs), R{}};
}
Expand All @@ -49,7 +49,8 @@ struct delta_ {
template<Reference R>
struct absolute_ {
template<typename FwdRep, RepresentationOf<get_quantity_spec(R{}).character> Rep = std::remove_cvref_t<FwdRep>>
[[nodiscard]] constexpr quantity_point<R{}, default_point_origin(R{}), Rep> operator()(FwdRep&& lhs) const
[[nodiscard]] constexpr quantity_point<MP_UNITS_EXPRESSION_WORKAROUND(R{}), default_point_origin(R{}), Rep>
operator()(FwdRep&& lhs) const
{
return quantity_point{quantity{std::forward<FwdRep>(lhs), R{}}};
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/include/mp-units/framework/dimension_concepts.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void to_base_specialization_of_base_dimension(const volatile base_dimension<Symb

template<typename T>
constexpr bool is_derived_from_specialization_of_base_dimension =
requires(T* t) { to_base_specialization_of_base_dimension(t); };
requires(T* type) { to_base_specialization_of_base_dimension(type); };

/**
* @brief A concept matching all named base dimensions in the library.
Expand Down
11 changes: 5 additions & 6 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,24 @@ 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;
using 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
3 changes: 2 additions & 1 deletion src/core/include/mp-units/framework/magnitude.h
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,8 @@ template<auto... Ms>
void to_base_specialization_of_magnitude(const volatile magnitude<Ms...>*);

template<typename T>
constexpr bool is_derived_from_specialization_of_magnitude = requires(T* t) { to_base_specialization_of_magnitude(t); };
constexpr bool is_derived_from_specialization_of_magnitude =
requires(T* type) { to_base_specialization_of_magnitude(type); };

template<typename T>
requires is_derived_from_specialization_of_magnitude<T>
Expand Down
Loading