diff --git a/app/src/main/cpp/skyline/common.h b/app/src/main/cpp/skyline/common.h index 211826ea..a0e77323 100644 --- a/app/src/main/cpp/skyline/common.h +++ b/app/src/main/cpp/skyline/common.h @@ -71,15 +71,53 @@ namespace skyline { /** * @note Success is 0, it's the only result that's not specific to a module */ - Result() = default; + constexpr Result() = default; - constexpr Result(u16 module, u16 id) : module(module), id(id) {} + constexpr explicit Result(u16 module, u16 id) : module(module), id(id) {} constexpr operator u32() const { return raw; } }; + /** + * @brief A wrapper around std::optional that also stores a HOS result code + * @tparam T The object type to hold + */ + template + class ResultValue { + static_assert(!std::is_same::value); + + private: + std::optional value; + + public: + Result result; + + constexpr ResultValue(T value) : value(value) {}; + + constexpr ResultValue(Result result) : result(result) {}; + + template + constexpr ResultValue(ResultValue result) : result(result) {}; + + constexpr operator Result() const { + return result; + } + + explicit constexpr operator bool() const { + return value.has_value(); + } + + constexpr T& operator*() { + return *value; + } + + constexpr T* operator->() { + return &*value; + } + }; + namespace constant { // Display constexpr u16 HandheldResolutionW{1280}; //!< The width component of the handheld resolution