1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-12-18 16:32:05 +00:00

ams: may as well test removal of CRTP from Result

This commit is contained in:
Michael Scire 2024-05-26 15:40:06 -07:00 committed by SciresM
parent 1609f804f2
commit 05fde7b764

View file

@ -85,14 +85,13 @@ namespace ams {
}; };
/* Use CRTP for Results. */ /* Use CRTP for Results. */
template<typename Self>
class ResultBase { class ResultBase {
public: public:
using BaseType = typename ResultTraits::BaseType; using BaseType = typename ResultTraits::BaseType;
static constexpr BaseType SuccessValue = ResultTraits::SuccessValue; static constexpr BaseType SuccessValue = ResultTraits::SuccessValue;
public: public:
constexpr ALWAYS_INLINE BaseType GetModule() const { return ResultTraits::GetModuleFromValue(static_cast<const Self *>(this)->GetValue()); } constexpr ALWAYS_INLINE BaseType GetModule(this auto const &self) { return ResultTraits::GetModuleFromValue(self.GetValue()); }
constexpr ALWAYS_INLINE BaseType GetDescription() const { return ResultTraits::GetDescriptionFromValue(static_cast<const Self *>(this)->GetValue()); } constexpr ALWAYS_INLINE BaseType GetDescription(this auto const &self) { return ResultTraits::GetDescriptionFromValue(self.GetValue()); }
}; };
class ResultInternalAccessor; class ResultInternalAccessor;
@ -101,10 +100,10 @@ namespace ams {
class ResultSuccess; class ResultSuccess;
class Result final : public result::impl::ResultBase<Result> { class Result final : public result::impl::ResultBase {
friend class result::impl::ResultInternalAccessor; friend class result::impl::ResultInternalAccessor;
public: public:
using Base = typename result::impl::ResultBase<Result>; using Base = typename result::impl::ResultBase;
private: private:
typename Base::BaseType m_value; typename Base::BaseType m_value;
private: private:
@ -157,9 +156,9 @@ namespace ams {
} }
class ResultSuccess final : public result::impl::ResultBase<ResultSuccess> { class ResultSuccess final : public result::impl::ResultBase {
public: public:
using Base = typename result::impl::ResultBase<ResultSuccess>; using Base = typename result::impl::ResultBase;
public: public:
constexpr ALWAYS_INLINE operator Result() const { return result::impl::MakeResult(Base::SuccessValue); } constexpr ALWAYS_INLINE operator Result() const { return result::impl::MakeResult(Base::SuccessValue); }
static constexpr ALWAYS_INLINE bool CanAccept(Result result) { return result.IsSuccess(); } static constexpr ALWAYS_INLINE bool CanAccept(Result result) { return result.IsSuccess(); }
@ -189,9 +188,9 @@ namespace ams {
namespace result::impl { namespace result::impl {
template<ResultTraits::BaseType _Module, ResultTraits::BaseType _Description> template<ResultTraits::BaseType _Module, ResultTraits::BaseType _Description>
class ResultErrorBase : public ResultBase<ResultErrorBase<_Module, _Description>> { class ResultErrorBase : public ResultBase {
public: public:
using Base = typename result::impl::ResultBase<ResultErrorBase<_Module, _Description>>; using Base = typename result::impl::ResultBase;
static constexpr typename Base::BaseType Module = _Module; static constexpr typename Base::BaseType Module = _Module;
static constexpr typename Base::BaseType Description = _Description; static constexpr typename Base::BaseType Description = _Description;
static constexpr typename Base::BaseType Value = ResultTraits::MakeStaticValue<Module, Description>::value; static constexpr typename Base::BaseType Value = ResultTraits::MakeStaticValue<Module, Description>::value;