plcopen 0.22.0
载入中...
搜索中...
未找到
error.h
浏览该文件的文档.
1#pragma once
2
3namespace plcopen::core::rt
4{
5
20
21template <typename T> class Result
22{
23public:
24 static constexpr Result success(const T &value)
25 {
26 return Result(true, ErrorCode::ok, value);
27 }
28
29 static constexpr Result failure(ErrorCode error)
30 {
31 return Result(false, error, T{});
32 }
33
34 constexpr explicit operator bool() const
35 {
36 return ok_;
37 }
38
39 constexpr bool ok() const
40 {
41 return ok_;
42 }
43
44 constexpr ErrorCode error() const
45 {
46 return error_;
47 }
48
49 constexpr const T &value() const
50 {
51 return value_;
52 }
53
54 constexpr T &value()
55 {
56 return value_;
57 }
58
59private:
60 constexpr Result(bool ok, ErrorCode error, const T &value)
61 : ok_(ok)
62 , error_(error)
63 , value_(value)
64 {
65 }
66
67 bool ok_ = false;
69 T value_{};
70};
71
72} // namespace plcopen::core::rt
constexpr const T & value() const
定义 error.h:49
constexpr bool ok() const
定义 error.h:39
constexpr ErrorCode error() const
定义 error.h:44
static constexpr Result success(const T &value)
定义 error.h:24
static constexpr Result failure(ErrorCode error)
定义 error.h:29
constexpr T & value()
定义 error.h:54