Downcasting facility refactoring

This commit is contained in:
Mateusz Pusz
2019-11-02 13:54:43 +01:00
parent 219af8e173
commit 2bde0e62b2
9 changed files with 58 additions and 47 deletions
+4 -4
View File
@@ -41,8 +41,8 @@ namespace units {
std::derived_from<T, downcast_base<typename T::base_type>>;
template<typename Target, Downcastable T>
struct downcast_helper : T {
friend auto downcast_guide(typename downcast_helper::downcast_base) { return Target(); }
struct downcast_child : T {
friend auto downcast_guide(typename downcast_child::downcast_base) { return Target(); }
};
namespace detail {
@@ -53,7 +53,7 @@ namespace units {
};
template<typename T>
constexpr auto downcast_target_impl()
constexpr auto downcast_impl()
{
if constexpr(has_downcast<T>)
return decltype(downcast_guide(std::declval<downcast_base<T>>()))();
@@ -64,7 +64,7 @@ namespace units {
}
template<Downcastable T>
using downcast_target = decltype(detail::downcast_target_impl<T>());
using downcast = decltype(detail::downcast_impl<T>());
template<Downcastable T>
using downcast_base_t = T::base_type;
+1 -1
View File
@@ -48,7 +48,7 @@ namespace units {
{
if constexpr(Ratio::num != 1 || Ratio::den != 1) {
if(!std::same_as<PrefixType, no_prefix>) {
using prefix = downcast_target<detail::prefix_base<PrefixType, Ratio>>;
using prefix = downcast<detail::prefix_base<PrefixType, Ratio>>;
if constexpr(!std::same_as<prefix, prefix_base<PrefixType, Ratio>>) {
// print as a prefixed unit