mirror of
https://github.com/jkcoxson/idevice.git
synced 2026-03-02 06:26:15 +01:00
Add cpp bindings for image mounter
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdio>
|
||||
#include <stdexcept>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
@@ -115,6 +116,34 @@ template <typename T> class Option {
|
||||
return has_ ? std::move(*ptr()) : static_cast<T>(f());
|
||||
}
|
||||
|
||||
T expect(const char* message) && {
|
||||
if (is_none()) {
|
||||
std::fprintf(stderr, "Fatal (expect) error: %s\n", message);
|
||||
std::terminate();
|
||||
}
|
||||
T tmp = std::move(*ptr());
|
||||
reset();
|
||||
return tmp;
|
||||
}
|
||||
|
||||
// Returns a mutable reference from an lvalue Result
|
||||
T& expect(const char* message) & {
|
||||
if (is_none()) {
|
||||
std::fprintf(stderr, "Fatal (expect) error: %s\n", message);
|
||||
std::terminate();
|
||||
}
|
||||
return *ptr();
|
||||
}
|
||||
|
||||
// Returns a const reference from a const lvalue Result
|
||||
const T& expect(const char* message) const& {
|
||||
if (is_none()) {
|
||||
std::fprintf(stderr, "Fatal (expect) error: %s\n", message);
|
||||
std::terminate();
|
||||
}
|
||||
return *ptr();
|
||||
}
|
||||
|
||||
// map
|
||||
template <typename F>
|
||||
auto map(F&& f) const& -> Option<typename std::decay<decltype(f(*ptr()))>::type> {
|
||||
|
||||
Reference in New Issue
Block a user