gimo v0.1.0
Loading...
Searching...
No Matches
StdExpected.hpp
Go to the documentation of this file.
1// Copyright Dominic (DNKpp) Koepke 2025.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at
4// https://www.boost.org/LICENSE_1_0.txt)
5
6#ifndef GIMO_EXT_STD_EXPECTED_HPP
7#define GIMO_EXT_STD_EXPECTED_HPP
8
9#pragma once
10
11#include <expected>
12
13namespace gimo
14{
15 template <typename T>
16 struct traits;
17}
18
19template <typename Value, typename Error>
20struct gimo::traits<std::expected<Value, Error>>
21{
22 using expected = std::expected<Value, Error>;
23
24 struct null_t
25 {
26 [[nodiscard]]
27 friend constexpr bool operator==(expected const& expected, [[maybe_unused]] null_t const tag) noexcept
28 {
29 return !expected.has_value();
30 }
31
32 [[nodiscard]]
33 explicit(false) constexpr operator expected() const noexcept
34 {
35 return expected{};
36 }
37 };
38
39 static constexpr null_t null{};
40
41 template <typename V>
42 using rebind_value = std::expected<V, Error>;
43
44 template <typename E>
45 using rebind_error = std::expected<Value, E>;
46
47 template <typename E>
48 requires std::constructible_from<expected, std::unexpect_t, E&&>
49 static constexpr expected from_error(E&& error)
50 {
51 return expected{std::unexpect, std::forward<E>(error)};
52 }
53};
54
55#endif
Definition AndThen.hpp:21
friend constexpr bool operator==(expected const &expected, null_t const tag) noexcept
Definition StdExpected.hpp:27
std::expected< V, Error > rebind_value
Definition StdExpected.hpp:42
static constexpr null_t null
Definition StdExpected.hpp:39
static constexpr expected from_error(E &&error)
Definition StdExpected.hpp:49
std::expected< Value, E > rebind_error
Definition StdExpected.hpp:45
std::expected< Value, Error > expected
Definition StdExpected.hpp:22
The central customization point for the library.
Definition Common.hpp:102