#pragma once #include #include #include namespace ztu { template using result = std::expected; /* template class result { static constexpr auto value_index = 0; static constexpr auto error_index = 1; public: constexpr result(T value); constexpr result(const std::error_code& error); template void emplace(Args&&... args); [[nodiscard]] constexpr bool ok() const; [[nodiscard]] constexpr std::error_code error() const; [[nodiscard]] constexpr const T& value() const; [[nodiscard]] constexpr T& value(); [[nodiscard]] constexpr T&& value() &&; [[nodiscard]] operator bool() const; [[nodiscard]] const T& operator*() const; [[nodiscard]] T& operator*(); [[nodiscard]] T&& operator*() &&; [[nodiscard]] bool operator==(const T& rhs) const; [[nodiscard]] bool operator==(const std::error_code& rhs) const; template auto map(Func&& func) const -> result { if (ok()) return func(value()); return error(); } private: std::variant m_data; }; // Member function definitions template constexpr result::result(T value) : m_data{ std::in_place_index_t{}, std::move(value) } {} template constexpr result::result(const std::error_code& error) : m_data{ std::in_place_index_t{}, error } {} template template void result::emplace(Args&&... args) { m_data.template emplace(std::forward(args)...); } template template auto result::map(Func&& func) const -> result { if (ok()) return func(value()); return error(); } template constexpr bool result::ok() const { return m_data.index() == value_index; } template constexpr std::error_code result::error() const { auto error_ptr = std::get_if(m_data); return error_ptr ? *error_ptr : std::error_code{}; } template constexpr const T& result::value() const { return std::get(m_data); } template constexpr T& result::value() { return std::get(m_data); } template constexpr T&& result::value() && { return std::get(std::move(m_data)); } template constexpr result::operator bool() const { return ok(); } template const T& result::operator*() const { return *std::get_if(m_data); } template T& result::operator*() { return *std::get_if(m_data); } template T&& result::operator*() && { return *std::get_if(std::move(m_data)); } template bool result::operator==(const T& rhs) const { return ok() and value() == rhs; } template bool result::operator==(const std::error_code& rhs) const { return not ok() and error() == rhs; }*/ }