• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- A data structure for returning an error or a value ------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_LIBC_SRC___SUPPORT_ERROR_OR_H
10 #define LLVM_LIBC_SRC___SUPPORT_ERROR_OR_H
11 
12 #include "src/__support/CPP/expected.h"
13 
14 namespace LIBC_NAMESPACE {
15 
16 template <class T> using ErrorOr = cpp::expected<T, int>;
17 
18 using Error = cpp::unexpected<int>;
19 
20 // template <typename T> struct ErrorOr {
21 //   union {
22 //     T value;
23 //     int error;
24 //   };
25 //   bool is_error;
26 
27 //   constexpr ErrorOr(T value) : value(value), is_error(false) {}
28 //   constexpr ErrorOr(int error, bool is_error)
29 //       : error(error), is_error(is_error) {}
30 
31 //   constexpr bool has_error() { return is_error; }
32 
33 //   constexpr operator bool() { return is_error; }
34 //   constexpr operator T() { return value; }
35 // };
36 
37 } // namespace LIBC_NAMESPACE
38 
39 #endif // LLVM_LIBC_SRC___SUPPORT_ERROR_OR_H
40