mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-05 21:24:27 +02:00
fix: downcasting facility for non-default-constructible types
This commit is contained in:
committed by
Mateusz Pusz
parent
02ea4825e8
commit
052d818385
@@ -21,6 +21,7 @@
|
||||
- fix: quantity's operators fixed to behave like the underlying types do
|
||||
- fix: `quantity_cast()` fixed to work correctly with representation types not convertible from `std::intmax_t`
|
||||
- fix: ambiguous case for empty type list resolved
|
||||
- fix: downcasting facility for non-default-constructible types
|
||||
- (!) build: `BUILD_DOCS` CMake option renamed to `UNITS_BUILD_DOCS`
|
||||
- build: doxygen updated to 1.8.20
|
||||
- build: catch2 updated to 2.13.4
|
||||
|
@@ -56,7 +56,7 @@ concept has_downcast_poison_pill = requires(T t) { downcast_poison_pill(t); };
|
||||
template<typename Target, Downcastable T>
|
||||
struct downcast_child : T {
|
||||
friend auto downcast_guide(typename T::downcast_base)
|
||||
{ return Target(); }
|
||||
{ return std::type_identity<Target>(); }
|
||||
};
|
||||
|
||||
template<Downcastable T>
|
||||
@@ -89,13 +89,13 @@ constexpr auto downcast_impl()
|
||||
if constexpr(has_downcast_guide<T> && !has_downcast_poison_pill<T>)
|
||||
return decltype(downcast_guide(std::declval<downcast_base<T>>()))();
|
||||
else
|
||||
return T();
|
||||
return std::type_identity<T>();
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<Downcastable T>
|
||||
using downcast = decltype(detail::downcast_impl<T>());
|
||||
using downcast = TYPENAME decltype(detail::downcast_impl<T>())::type;
|
||||
|
||||
template<Downcastable T>
|
||||
using downcast_base_t = TYPENAME T::downcast_base_type;
|
||||
|
Reference in New Issue
Block a user