tqchen commented on code in PR #399: URL: https://github.com/apache/tvm-ffi/pull/399#discussion_r2754332863
########## include/tvm/ffi/expected.h: ########## @@ -0,0 +1,218 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * \file tvm/ffi/expected.h + * \brief Runtime Expected container type for exception-free error handling. + */ +#ifndef TVM_FFI_EXPECTED_H_ +#define TVM_FFI_EXPECTED_H_ + +#include <tvm/ffi/any.h> +#include <tvm/ffi/error.h> + +#include <type_traits> +#include <utility> + +namespace tvm { +namespace ffi { + +/*! + * \brief Wrapper to explicitly construct an Expected in the error state. + */ +struct Unexpected { + /*! \brief Construct from an error. */ + // NOLINTNEXTLINE(google-explicit-constructor,runtime/explicit) + Unexpected(Error error) : error_(std::move(error)) {} + /*! \brief The wrapped error. */ + Error error_; Review Comment: consider align with `std::unexpected<E>` API, make it a class and keep it an private member. The error can be accessed via error() member function https://en.cppreference.com/w/cpp/utility/expected/unexpected.html Would be good to see if we can use Unexpected<E> for E as subclass of Error if such auto deduction is possible. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
