summaryrefslogtreecommitdiff
path: root/AK/Error.h
blob: b91721920d0940836261a48ef62618b82a681dad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#pragma once

#include <AK/Platform.h>

namespace AK {

template <typename T, auto NoErrorValue>
class CONSUMABLE(unknown) Error {
public:
    RETURN_TYPESTATE(unknown)
    Error()
        : t(NoErrorValue)
    {}

    RETURN_TYPESTATE(unknown)
    Error(T t)
        : t(t)
    {}

    RETURN_TYPESTATE(unknown)
    Error(Error&& other)
        : t(move(other.t))
    {
    }

    RETURN_TYPESTATE(unknown)
    Error(const Error& other)
        : t(other.t)
    {
    }

    CALLABLE_WHEN("unknown", "consumed")
    ~Error() {}

    SET_TYPESTATE(consumed)
    bool failed() const {
        return t != NoErrorValue;
    }

    [[deprecated]]
    SET_TYPESTATE(consumed)
    void ignore() {}

    const T& value() const { return t; }

    bool operator==(const Error& o) { return t == o.t; }
    bool operator!=(const Error& o) { return t != o.t; }
    T t;
};

}

using AK::Error;