libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
result.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <promeki/core/pair.h>
11#include <promeki/core/error.h>
12
14
24template <typename T>
26
33template <typename T>
35 return Result<T>(std::move(value), Error::Ok);
36}
37
44template <typename T>
46 return Result<T>(T{}, std::move(err));
47}
48
55template <typename T>
56const T &value(const Result<T> &r) { return r.first(); }
57
64template <typename T>
65const Error &error(const Result<T> &r) { return r.second(); }
66
73template <typename T>
74bool isOk(const Result<T> &r) { return r.second().isOk(); }
75
82template <typename T>
83bool isError(const Result<T> &r) { return r.second().isError(); }
84
Lightweight error code wrapper for the promeki library.
Definition error.h:39
@ Ok
No error.
Definition error.h:51
Dynamic array container wrapping std::vector.
Definition list.h:40
#define PROMEKI_NAMESPACE_BEGIN
Starts a promeki namespace block.
Definition namespace.h:14
#define PROMEKI_NAMESPACE_END
Ends a promeki namespace block.
Definition namespace.h:19
bool isError(const Result< T > &r)
Returns true if the Result has an error.
Definition result.h:83
const T & value(const Result< T > &r)
Returns the value from a Result.
Definition result.h:56
bool isOk(const Result< T > &r)
Returns true if the Result is successful (Error::Ok).
Definition result.h:74
Result< T > makeResult(T value)
Creates a successful Result wrapping value.
Definition result.h:34
const Error & error(const Result< T > &r)
Returns the error from a Result.
Definition result.h:65
Result< T > makeError(Error err)
Creates an error Result with a default-constructed value.
Definition result.h:45