Down with typename

This commit is contained in:
Mateusz Pusz
2019-04-11 17:40:54 +01:00
parent d75377ccaf
commit 4b6a7ebb39
7 changed files with 38 additions and 38 deletions

View File

@@ -127,7 +127,7 @@ struct make_dimension {
}; };
template<Exponent... Es> template<Exponent... Es>
using make_dimension_t = typename make_dimension<Es...>::type; using make_dimension_t = make_dimension<Es...>::type;
``` ```
So for example to create a `dimension_velocity` type we have to do: So for example to create a `dimension_velocity` type we have to do:
@@ -172,7 +172,7 @@ struct dimension_multiply<dimension<E1...>, dimension<E2...>> {
}; };
template<Dimension D1, Dimension D2> template<Dimension D1, Dimension D2>
using dimension_multiply_t = typename dimension_multiply<typename D1::base_type, typename D2::base_type>::type; using dimension_multiply_t = dimension_multiply<typename D1::base_type, typename D2::base_type>::type;
``` ```
Example implementation of `merge_dimension` may look like: Example implementation of `merge_dimension` may look like:
@@ -361,7 +361,7 @@ Upcasting capability is provided through dedicated `upcasting_traits`, a few hel
```cpp ```cpp
template<Upcastable T> template<Upcastable T>
using upcast_from = typename T::base_type; using upcast_from = T::base_type;
template<typename T> template<typename T>
using upcast_to = std::type_identity<T>; using upcast_to = std::type_identity<T>;
@@ -370,7 +370,7 @@ template<typename T>
struct upcasting_traits : upcast_to<T> {}; struct upcasting_traits : upcast_to<T> {};
template<typename T> template<typename T>
using upcasting_traits_t = typename upcasting_traits<T>::type; using upcasting_traits_t = upcasting_traits<T>::type;
``` ```
With that the upcasting functionality is enabled by: With that the upcasting functionality is enabled by:

View File

@@ -79,6 +79,6 @@ namespace units {
}; };
template<Ratio R1, Ratio R2> template<Ratio R1, Ratio R2>
using common_ratio_t = typename common_ratio<R1, R2>::type; using common_ratio_t = common_ratio<R1, R2>::type;
} // namespace units } // namespace units

View File

@@ -50,7 +50,7 @@ namespace units {
}; };
template<TypeList List, typename... Types> template<TypeList List, typename... Types>
using type_list_push_front_t = typename type_list_push_front<List, Types...>::type; using type_list_push_front_t = type_list_push_front<List, Types...>::type;
// push_back // push_back
@@ -63,7 +63,7 @@ namespace units {
}; };
template<TypeList List, typename... Types> template<TypeList List, typename... Types>
using type_list_push_back_t = typename type_list_push_back<List, Types...>::type; using type_list_push_back_t = type_list_push_back<List, Types...>::type;
// split // split
@@ -81,8 +81,8 @@ namespace units {
template<template<typename...> typename List, std::size_t Idx, std::size_t N, typename T, typename... Rest> template<template<typename...> typename List, std::size_t Idx, std::size_t N, typename T, typename... Rest>
struct split_impl<List, Idx, N, T, Rest...> : split_impl<List, Idx + 1, N, Rest...> { struct split_impl<List, Idx, N, T, Rest...> : split_impl<List, Idx + 1, N, Rest...> {
using base = split_impl<List, Idx + 1, N, Rest...>; using base = split_impl<List, Idx + 1, N, Rest...>;
using base_first = typename base::first_list; using base_first = base::first_list;
using base_second = typename base::second_list; using base_second = base::second_list;
using first_list = std::conditional_t<Idx < N, type_list_push_front_t<base_first, T>, base_first>; using first_list = std::conditional_t<Idx < N, type_list_push_front_t<base_first, T>, base_first>;
using second_list = std::conditional_t<Idx < N, base_second, type_list_push_front_t<base_second, T>>; using second_list = std::conditional_t<Idx < N, base_second, type_list_push_front_t<base_second, T>>;
}; };
@@ -96,8 +96,8 @@ namespace units {
struct type_list_split<List<Types...>, N> { struct type_list_split<List<Types...>, N> {
static_assert(N <= sizeof...(Types), "Invalid index provided"); static_assert(N <= sizeof...(Types), "Invalid index provided");
using split = detail::split_impl<List, 0, N, Types...>; using split = detail::split_impl<List, 0, N, Types...>;
using first_list = typename split::first_list; using first_list = split::first_list;
using second_list = typename split::second_list; using second_list = split::second_list;
}; };
// split_half // split_half
@@ -115,7 +115,7 @@ namespace units {
struct type_list_merge_sorted; struct type_list_merge_sorted;
template<TypeList SortedList1, TypeList SortedList2, template<typename, typename> typename Pred> template<TypeList SortedList1, TypeList SortedList2, template<typename, typename> typename Pred>
using type_list_merge_sorted_t = typename type_list_merge_sorted<SortedList1, SortedList2, Pred>::type; using type_list_merge_sorted_t = type_list_merge_sorted<SortedList1, SortedList2, Pred>::type;
template<template<typename...> typename List, typename... Lhs, template<typename, typename> typename Pred> template<template<typename...> typename List, typename... Lhs, template<typename, typename> typename Pred>
struct type_list_merge_sorted<List<Lhs...>, List<>, Pred> { struct type_list_merge_sorted<List<Lhs...>, List<>, Pred> {
@@ -155,12 +155,12 @@ namespace units {
struct type_list_sort<List<Types...>, Pred> { struct type_list_sort<List<Types...>, Pred> {
using types = List<Types...>; using types = List<Types...>;
using split = type_list_split_half<List<Types...>>; using split = type_list_split_half<List<Types...>>;
using left = typename type_list_sort<typename split::first_list, Pred>::type; using left = type_list_sort<typename split::first_list, Pred>::type;
using right = typename type_list_sort<typename split::second_list, Pred>::type; using right = type_list_sort<typename split::second_list, Pred>::type;
using type = type_list_merge_sorted_t<left, right, Pred>; using type = type_list_merge_sorted_t<left, right, Pred>;
}; };
template<TypeList List, template<typename, typename> typename Pred> template<TypeList List, template<typename, typename> typename Pred>
using type_list_sort_t = typename type_list_sort<List, Pred>::type; using type_list_sort_t = type_list_sort<List, Pred>::type;
} // namespace units } // namespace units

View File

@@ -40,15 +40,15 @@ namespace units {
std::DerivedFrom<T, upcast_base<typename T::base_type>>; std::DerivedFrom<T, upcast_base<typename T::base_type>>;
template<Upcastable T> template<Upcastable T>
using upcast_from = typename T::base_type; using upcast_from = T::base_type;
template<Upcastable T> template<Upcastable T>
using upcast_to = typename std::type_identity<T>; using upcast_to = std::type_identity<T>;
template<Upcastable T> template<Upcastable T>
struct upcasting_traits : upcast_to<T> {}; struct upcasting_traits : upcast_to<T> {};
template<Upcastable T> template<Upcastable T>
using upcasting_traits_t = typename upcasting_traits<T>::type; using upcasting_traits_t = upcasting_traits<T>::type;
} // namespace units } // namespace units

View File

@@ -82,7 +82,7 @@ namespace units {
}; };
template<Exponent E> template<Exponent E>
using exp_invert_t = typename exp_invert<E>::type; using exp_invert_t = exp_invert<E>::type;
// dimension // dimension
@@ -115,7 +115,7 @@ namespace units {
struct dim_invert<dimension<Es...>> : std::type_identity<upcasting_traits_t<dimension<exp_invert_t<Es>...>>> {}; struct dim_invert<dimension<Es...>> : std::type_identity<upcasting_traits_t<dimension<exp_invert_t<Es>...>>> {};
template<Dimension D> template<Dimension D>
using dim_invert_t = typename dim_invert<typename D::base_type>::type; using dim_invert_t = dim_invert<typename D::base_type>::type;
// make_dimension // make_dimension
@@ -126,7 +126,7 @@ namespace units {
struct dim_consolidate; struct dim_consolidate;
template<Dimension D> template<Dimension D>
using dim_consolidate_t = typename dim_consolidate<D>::type; using dim_consolidate_t = dim_consolidate<D>::type;
template<> template<>
struct dim_consolidate<dimension<>> { struct dim_consolidate<dimension<>> {
@@ -159,7 +159,7 @@ namespace units {
}; };
template<Exponent... Es> template<Exponent... Es>
using make_dimension_t = typename make_dimension<Es...>::type; using make_dimension_t = make_dimension<Es...>::type;
template<Dimension D1, Dimension D2> template<Dimension D1, Dimension D2>
struct merge_dimension { struct merge_dimension {
@@ -167,7 +167,7 @@ namespace units {
}; };
template<Dimension D1, Dimension D2> template<Dimension D1, Dimension D2>
using merge_dimension_t = typename merge_dimension<D1, D2>::type; using merge_dimension_t = merge_dimension<D1, D2>::type;
// dimension_multiply // dimension_multiply
@@ -178,7 +178,7 @@ namespace units {
struct dimension_multiply<dimension<E1...>, dimension<E2...>> : std::type_identity<upcasting_traits_t<merge_dimension_t<dimension<E1...>, dimension<E2...>>>> {}; struct dimension_multiply<dimension<E1...>, dimension<E2...>> : std::type_identity<upcasting_traits_t<merge_dimension_t<dimension<E1...>, dimension<E2...>>>> {};
template<Dimension D1, Dimension D2> template<Dimension D1, Dimension D2>
using dimension_multiply_t = typename dimension_multiply<typename D1::base_type, typename D2::base_type>::type; using dimension_multiply_t = dimension_multiply<typename D1::base_type, typename D2::base_type>::type;
// dimension_divide // dimension_divide
@@ -191,6 +191,6 @@ namespace units {
}; };
template<Dimension D1, Dimension D2> template<Dimension D1, Dimension D2>
using dimension_divide_t = typename dimension_divide<typename D1::base_type, typename D2::base_type>::type; using dimension_divide_t = dimension_divide<typename D1::base_type, typename D2::base_type>::type;
} // namespace units } // namespace units

View File

@@ -71,7 +71,7 @@ namespace units {
}; };
template<Quantity Q1, Quantity Q2, Scalar Rep = std::common_type_t<typename Q1::rep, typename Q2::rep>> template<Quantity Q1, Quantity Q2, Scalar Rep = std::common_type_t<typename Q1::rep, typename Q2::rep>>
using common_quantity_t = typename common_quantity<Q1, Q2, Rep>::type; using common_quantity_t = common_quantity<Q1, Q2, Rep>::type;
// treat_as_floating_point // treat_as_floating_point
@@ -87,7 +87,7 @@ namespace units {
template<Quantity Q> template<Quantity Q>
static constexpr To cast(const Q& q) static constexpr To cast(const Q& q)
{ {
return To(static_cast<typename To::rep>(static_cast<CRep>(q.count()) * static_cast<CRep>(CR::num) / return To(static_cast<To::rep>(static_cast<CRep>(q.count()) * static_cast<CRep>(CR::num) /
static_cast<CRep>(CR::den))); static_cast<CRep>(CR::den)));
} }
}; };
@@ -97,7 +97,7 @@ namespace units {
template<Quantity Q> template<Quantity Q>
static constexpr To cast(const Q& q) static constexpr To cast(const Q& q)
{ {
return To(static_cast<typename To::rep>(q.count())); return To(static_cast<To::rep>(q.count()));
} }
}; };
@@ -106,7 +106,7 @@ namespace units {
template<Quantity Q> template<Quantity Q>
static constexpr To cast(const Q& q) static constexpr To cast(const Q& q)
{ {
return To(static_cast<typename To::rep>(static_cast<CRep>(q.count()) / static_cast<CRep>(CR::den))); return To(static_cast<To::rep>(static_cast<CRep>(q.count()) / static_cast<CRep>(CR::den)));
} }
}; };
@@ -115,7 +115,7 @@ namespace units {
template<Quantity Q> template<Quantity Q>
static constexpr To cast(const Q& q) static constexpr To cast(const Q& q)
{ {
return To(static_cast<typename To::rep>(static_cast<CRep>(q.count()) * static_cast<CRep>(CR::num))); return To(static_cast<To::rep>(static_cast<CRep>(q.count()) * static_cast<CRep>(CR::num)));
} }
}; };
@@ -183,8 +183,8 @@ namespace units {
[[nodiscard]] static constexpr quantity min() noexcept { return quantity(quantity_values<Rep>::min()); } [[nodiscard]] static constexpr quantity min() noexcept { return quantity(quantity_values<Rep>::min()); }
[[nodiscard]] static constexpr quantity max() noexcept { return quantity(quantity_values<Rep>::max()); } [[nodiscard]] static constexpr quantity max() noexcept { return quantity(quantity_values<Rep>::max()); }
[[nodiscard]] constexpr quantity operator-() const { return quantity(-count()); }
[[nodiscard]] constexpr quantity operator+() const { return quantity(*this); } [[nodiscard]] constexpr quantity operator+() const { return quantity(*this); }
[[nodiscard]] constexpr quantity operator-() const { return quantity(-count()); }
constexpr quantity& operator++() constexpr quantity& operator++()
{ {

View File

@@ -62,7 +62,7 @@ namespace units {
template<Exponent E, Exponent... Rest> template<Exponent E, Exponent... Rest>
struct get_unit_base_dim<dimension<E, Rest...>> { struct get_unit_base_dim<dimension<E, Rest...>> {
static_assert(sizeof...(Rest) == 0, "Base unit expected"); static_assert(sizeof...(Rest) == 0, "Base unit expected");
using dimension = typename E::dimension; using dimension = E::dimension;
}; };
template<typename BaseDimension, Unit... Us> template<typename BaseDimension, Unit... Us>
@@ -72,7 +72,7 @@ namespace units {
template<typename BaseDimension, Unit U, Unit... Rest> template<typename BaseDimension, Unit U, Unit... Rest>
struct get_ratio<BaseDimension, U, Rest...> { struct get_ratio<BaseDimension, U, Rest...> {
using unit_base_dim = typename get_unit_base_dim<typename U::dimension::base_type>::dimension; using unit_base_dim = get_unit_base_dim<typename U::dimension::base_type>::dimension;
using ratio = std::conditional_t<unit_base_dim::value == BaseDimension::value, typename U::ratio, using ratio = std::conditional_t<unit_base_dim::value == BaseDimension::value, typename U::ratio,
typename get_ratio<BaseDimension, Rest...>::ratio>; typename get_ratio<BaseDimension, Rest...>::ratio>;
}; };
@@ -90,7 +90,7 @@ namespace units {
using calc_ratio = std::conditional_t<(UnitExpValue > 0), std::ratio_multiply<Result, UnitRatio>, using calc_ratio = std::conditional_t<(UnitExpValue > 0), std::ratio_multiply<Result, UnitRatio>,
std::ratio_divide<Result, UnitRatio>>; std::ratio_divide<Result, UnitRatio>>;
static constexpr int value = UnitExpValue > 0 ? UnitExpValue - 1 : UnitExpValue + 1; static constexpr int value = UnitExpValue > 0 ? UnitExpValue - 1 : UnitExpValue + 1;
using ratio = typename ratio_op<calc_ratio, value, UnitRatio>::ratio; using ratio = ratio_op<calc_ratio, value, UnitRatio>::ratio;
}; };
template<Dimension D, Unit... Us> template<Dimension D, Unit... Us>
@@ -103,9 +103,9 @@ namespace units {
template<Exponent E, Exponent... Rest, Unit... Us> template<Exponent E, Exponent... Rest, Unit... Us>
struct derived_ratio<dimension<E, Rest...>, Us...> { struct derived_ratio<dimension<E, Rest...>, Us...> {
using rest_ratio = typename derived_ratio<dimension<Rest...>, Us...>::ratio; using rest_ratio = derived_ratio<dimension<Rest...>, Us...>::ratio;
using e_ratio = typename get_ratio<typename E::dimension, Us...>::ratio; using e_ratio = get_ratio<typename E::dimension, Us...>::ratio;
using ratio = typename ratio_op<rest_ratio, E::value, e_ratio>::ratio; using ratio = ratio_op<rest_ratio, E::value, e_ratio>::ratio;
}; };
} }