mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-11 13:35:03 -04:00
Cleanup
This commit is contained in:
parent
4d95ac489e
commit
424e47a3aa
@ -17,41 +17,47 @@
|
|||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
|
|
||||||
constexpr struct only_set_valid_t {} only_set_valid;
|
constexpr struct only_set_valid_t {
|
||||||
|
} only_set_valid;
|
||||||
|
|
||||||
template <typename E>
|
template <typename E>
|
||||||
struct exceptional {
|
struct exceptional {
|
||||||
typedef E error_type;
|
using error_type = E; ///< The error type
|
||||||
|
|
||||||
error_type error;
|
error_type error; ///< The error value
|
||||||
|
|
||||||
exceptional(): error() {
|
exceptional()
|
||||||
|
: error() {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit exceptional(error_type e) : error(e) {
|
explicit exceptional(error_type e)
|
||||||
|
: error(e) {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, typename E>
|
template <typename T, typename E>
|
||||||
union trivial_expected_storage {
|
union trivial_expected_storage {
|
||||||
typedef T value_type;
|
using value_type = T; ///< The value type
|
||||||
typedef E error_type;
|
using error_type = E; ///< The error type
|
||||||
|
|
||||||
error_type error;
|
error_type error; ///< The error value
|
||||||
value_type value;
|
value_type value; ///< The value
|
||||||
|
|
||||||
constexpr trivial_expected_storage() : value(){
|
constexpr trivial_expected_storage()
|
||||||
|
: value() {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr trivial_expected_storage(const exceptional<error_type>& e) : error(e.error){
|
constexpr trivial_expected_storage(const exceptional<error_type>& e)
|
||||||
|
: error(e.error) {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
constexpr trivial_expected_storage(Args&&... args): value(std::forward<Args>(args)...){
|
constexpr trivial_expected_storage(Args&&... args)
|
||||||
|
: value(std::forward<Args>(args)...) {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,16 +66,17 @@ union trivial_expected_storage {
|
|||||||
|
|
||||||
template <typename E>
|
template <typename E>
|
||||||
union trivial_expected_storage<void, E> {
|
union trivial_expected_storage<void, E> {
|
||||||
typedef void value_type;
|
using value_type = Type; ///< The value type
|
||||||
typedef E error_type;
|
using error_type = E; ///< The error type
|
||||||
|
|
||||||
error_type error;
|
error_type error; ///< The error value
|
||||||
|
|
||||||
constexpr trivial_expected_storage() {
|
constexpr trivial_expected_storage() {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr trivial_expected_storage(const exceptional<error_type>& e) : error(e.error){
|
constexpr trivial_expected_storage(const exceptional<error_type>& e)
|
||||||
|
: error(e.error) {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,22 +85,25 @@ union trivial_expected_storage <void, E> {
|
|||||||
|
|
||||||
template <typename T, typename E>
|
template <typename T, typename E>
|
||||||
struct non_trivial_expected_storage {
|
struct non_trivial_expected_storage {
|
||||||
typedef T value_type;
|
using value_type = T; ///< The value type
|
||||||
typedef E error_type;
|
using error_type = E; ///< The error type
|
||||||
|
|
||||||
error_type error;
|
error_type error; ///< The error value
|
||||||
value_type value;
|
value_type value; ///< The value
|
||||||
|
|
||||||
constexpr non_trivial_expected_storage() : value(){
|
constexpr non_trivial_expected_storage()
|
||||||
|
: value() {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr non_trivial_expected_storage(const exceptional<error_type>& e) : error(e.error){
|
constexpr non_trivial_expected_storage(const exceptional<error_type>& e)
|
||||||
|
: error(e.error) {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
constexpr non_trivial_expected_storage(Args&&... args): value(std::forward<Args>(args)...){
|
constexpr non_trivial_expected_storage(Args&&... args)
|
||||||
|
: value(std::forward<Args>(args)...) {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,16 +112,17 @@ struct non_trivial_expected_storage {
|
|||||||
|
|
||||||
template <typename E>
|
template <typename E>
|
||||||
struct non_trivial_expected_storage<void, E> {
|
struct non_trivial_expected_storage<void, E> {
|
||||||
typedef void value_type;
|
using value_type = Type; ///< The value type
|
||||||
typedef E error_type;
|
using error_type = E; ///< The error type
|
||||||
|
|
||||||
error_type error;
|
error_type error; ///< The error value
|
||||||
|
|
||||||
constexpr non_trivial_expected_storage() {
|
constexpr non_trivial_expected_storage() {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr non_trivial_expected_storage(exceptional<error_type>& e) : error(e.error){
|
constexpr non_trivial_expected_storage(exceptional<error_type>& e)
|
||||||
|
: error(e.error) {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,29 +131,34 @@ struct non_trivial_expected_storage <void, E> {
|
|||||||
|
|
||||||
template <typename T, typename E>
|
template <typename T, typename E>
|
||||||
struct trivial_expected_base {
|
struct trivial_expected_base {
|
||||||
typedef T value_type;
|
using value_type = T; ///< The value type
|
||||||
typedef E error_type;
|
using error_type = E; ///< The error type
|
||||||
|
|
||||||
bool has_value;
|
bool has_value; ///< Indicates if the base has a value
|
||||||
trivial_expected_storage<T, E> storage;
|
trivial_expected_storage<T, E> storage;
|
||||||
|
|
||||||
trivial_expected_base() : has_value(true), storage(){
|
trivial_expected_base()
|
||||||
|
: has_value(true), storage() {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
|
|
||||||
trivial_expected_base(only_set_valid_t, bool hv) : has_value(hv){
|
trivial_expected_base(only_set_valid_t, bool hv)
|
||||||
|
: has_value(hv) {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
|
|
||||||
trivial_expected_base(const value_type& v) : has_value(true), storage(v){
|
trivial_expected_base(const value_type& v)
|
||||||
|
: has_value(true), storage(v) {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
|
|
||||||
trivial_expected_base(value_type&& v) : has_value(true), storage(std::forward<value_type>(v)){
|
trivial_expected_base(value_type&& v)
|
||||||
|
: has_value(true), storage(std::forward<value_type>(v)) {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
|
|
||||||
trivial_expected_base(const exceptional<error_type>& e) : has_value(false), storage(e) {
|
trivial_expected_base(const exceptional<error_type>& e)
|
||||||
|
: has_value(false), storage(e) {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,20 +167,23 @@ struct trivial_expected_base {
|
|||||||
|
|
||||||
template <typename E>
|
template <typename E>
|
||||||
struct trivial_expected_base<void, E> {
|
struct trivial_expected_base<void, E> {
|
||||||
typedef E error_type;
|
using error_type = E; ///< The error type
|
||||||
|
|
||||||
bool has_value;
|
bool has_value; ///< Indicates if the base has a value
|
||||||
trivial_expected_storage<void, E> storage;
|
trivial_expected_storage<void, E> storage;
|
||||||
|
|
||||||
trivial_expected_base() : has_value(true), storage(){
|
trivial_expected_base()
|
||||||
|
: has_value(true), storage() {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
|
|
||||||
trivial_expected_base(only_set_valid_t, bool hv) : has_value(hv){
|
trivial_expected_base(only_set_valid_t, bool hv)
|
||||||
|
: has_value(hv) {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
|
|
||||||
trivial_expected_base(const exceptional<error_type>& e) : has_value(false), storage(e) {
|
trivial_expected_base(const exceptional<error_type>& e)
|
||||||
|
: has_value(false), storage(e) {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,29 +192,34 @@ struct trivial_expected_base <void, E> {
|
|||||||
|
|
||||||
template <typename T, typename E>
|
template <typename T, typename E>
|
||||||
struct non_trivial_expected_base {
|
struct non_trivial_expected_base {
|
||||||
typedef T value_type;
|
using value_type = T; ///< The value type
|
||||||
typedef E error_type;
|
using error_type = E; ///< The error type
|
||||||
|
|
||||||
bool has_value;
|
bool has_value;
|
||||||
non_trivial_expected_storage<T, E> storage;
|
non_trivial_expected_storage<T, E> storage;
|
||||||
|
|
||||||
non_trivial_expected_base() : has_value(true), storage(){
|
non_trivial_expected_base()
|
||||||
|
: has_value(true), storage() {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
|
|
||||||
non_trivial_expected_base(only_set_valid_t, bool hv) : has_value(hv){
|
non_trivial_expected_base(only_set_valid_t, bool hv)
|
||||||
|
: has_value(hv) {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
|
|
||||||
non_trivial_expected_base(const value_type& v) : has_value(true), storage(v){
|
non_trivial_expected_base(const value_type& v)
|
||||||
|
: has_value(true), storage(v) {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
|
|
||||||
non_trivial_expected_base(value_type&& v) : has_value(true), storage(std::forward<value_type>(v)){
|
non_trivial_expected_base(value_type&& v)
|
||||||
|
: has_value(true), storage(std::forward<value_type>(v)) {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
|
|
||||||
non_trivial_expected_base(const exceptional<error_type>& e) : has_value(false), storage(e) {
|
non_trivial_expected_base(const exceptional<error_type>& e)
|
||||||
|
: has_value(false), storage(e) {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,20 +234,23 @@ struct non_trivial_expected_base {
|
|||||||
|
|
||||||
template <typename E>
|
template <typename E>
|
||||||
struct non_trivial_expected_base<void, E> {
|
struct non_trivial_expected_base<void, E> {
|
||||||
typedef E error_type;
|
using error_type = E; ///< The error type
|
||||||
|
|
||||||
bool has_value;
|
bool has_value; ///< Indicates if the base has a value
|
||||||
non_trivial_expected_storage<void, E> storage;
|
non_trivial_expected_storage<void, E> storage;
|
||||||
|
|
||||||
non_trivial_expected_base() : has_value(true), storage(){
|
non_trivial_expected_base()
|
||||||
|
: has_value(true), storage() {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
|
|
||||||
non_trivial_expected_base(only_set_valid_t, bool hv) : has_value(hv){
|
non_trivial_expected_base(only_set_valid_t, bool hv)
|
||||||
|
: has_value(hv) {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
|
|
||||||
non_trivial_expected_base(const exceptional<error_type>& e) : has_value(false), storage(e) {
|
non_trivial_expected_base(const exceptional<error_type>& e)
|
||||||
|
: has_value(false), storage(e) {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,13 +265,12 @@ template <typename T, typename E>
|
|||||||
using expected_base = std::conditional_t<
|
using expected_base = std::conditional_t<
|
||||||
std::is_trivially_destructible<T>::value && std::is_trivially_destructible<E>::value,
|
std::is_trivially_destructible<T>::value && std::is_trivially_destructible<E>::value,
|
||||||
trivial_expected_base<T, E>,
|
trivial_expected_base<T, E>,
|
||||||
non_trivial_expected_base<T, E>
|
non_trivial_expected_base<T, E>>;
|
||||||
>;
|
|
||||||
|
|
||||||
template <typename T, typename E = size_t>
|
template <typename T, typename E = size_t>
|
||||||
struct expected : expected_base<T, E> {
|
struct expected : expected_base<T, E> {
|
||||||
typedef T value_type;
|
using value_type = T; ///< The value type
|
||||||
typedef E error_type;
|
using error_type = E; ///< The error type
|
||||||
|
|
||||||
typedef expected<T, E> this_type;
|
typedef expected<T, E> this_type;
|
||||||
typedef expected_base<T, E> base_type;
|
typedef expected_base<T, E> base_type;
|
||||||
@ -305,15 +331,18 @@ private:
|
|||||||
public:
|
public:
|
||||||
/* Constructors */
|
/* Constructors */
|
||||||
|
|
||||||
constexpr expected(const value_type& v) : base_type(v){
|
constexpr expected(const value_type& v)
|
||||||
|
: base_type(v) {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr expected(value_type&& v) : base_type(std::forward<value_type>(v)){
|
constexpr expected(value_type&& v)
|
||||||
|
: base_type(std::forward<value_type>(v)) {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
|
|
||||||
expected(const expected& rhs) : base_type(only_set_valid, rhs.valid()) {
|
expected(const expected& rhs)
|
||||||
|
: base_type(only_set_valid, rhs.valid()) {
|
||||||
if (rhs.valid()) {
|
if (rhs.valid()) {
|
||||||
::new (value_ptr()) value_type(rhs.contained_value());
|
::new (value_ptr()) value_type(rhs.contained_value());
|
||||||
} else {
|
} else {
|
||||||
@ -321,7 +350,8 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
expected(expected&& rhs) : base_type(only_set_valid, rhs.valid()) {
|
expected(expected&& rhs)
|
||||||
|
: base_type(only_set_valid, rhs.valid()) {
|
||||||
if (rhs.valid()) {
|
if (rhs.valid()) {
|
||||||
new (value_ptr()) value_type(std::move(rhs.contained_value()));
|
new (value_ptr()) value_type(std::move(rhs.contained_value()));
|
||||||
} else {
|
} else {
|
||||||
@ -329,11 +359,13 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
expected(const exceptional<error_type>& e) : base_type(e) {
|
expected(const exceptional<error_type>& e)
|
||||||
|
: base_type(e) {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
|
|
||||||
expected() : base_type() {}
|
expected()
|
||||||
|
: base_type() {}
|
||||||
|
|
||||||
~expected() = default;
|
~expected() = default;
|
||||||
|
|
||||||
@ -424,8 +456,8 @@ public:
|
|||||||
|
|
||||||
template <typename E>
|
template <typename E>
|
||||||
struct expected<void, E> : expected_base<void, E> {
|
struct expected<void, E> : expected_base<void, E> {
|
||||||
typedef void value_type;
|
using value_type = void; ///< The value type
|
||||||
typedef E error_type;
|
using error_type = E; ///< The error type
|
||||||
|
|
||||||
typedef expected<void, E> this_type;
|
typedef expected<void, E> this_type;
|
||||||
typedef expected_base<void, E> base_type;
|
typedef expected_base<void, E> base_type;
|
||||||
@ -466,23 +498,27 @@ private:
|
|||||||
public:
|
public:
|
||||||
/* Constructors */
|
/* Constructors */
|
||||||
|
|
||||||
expected(const expected& rhs) : base_type(only_set_valid, rhs.valid()) {
|
expected(const expected& rhs)
|
||||||
|
: base_type(only_set_valid, rhs.valid()) {
|
||||||
if (!rhs.valid()) {
|
if (!rhs.valid()) {
|
||||||
::new (error_ptr()) error_type(rhs.contained_error());
|
::new (error_ptr()) error_type(rhs.contained_error());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
expected(expected&& rhs) : base_type(only_set_valid, rhs.valid()) {
|
expected(expected&& rhs)
|
||||||
|
: base_type(only_set_valid, rhs.valid()) {
|
||||||
if (!rhs.valid()) {
|
if (!rhs.valid()) {
|
||||||
new (error_ptr()) error_type(std::move(rhs.contained_error()));
|
new (error_ptr()) error_type(std::move(rhs.contained_error()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
expected(const exceptional<error_type>& e) : base_type(e) {
|
expected(const exceptional<error_type>& e)
|
||||||
|
: base_type(e) {
|
||||||
//Nothing else to init
|
//Nothing else to init
|
||||||
}
|
}
|
||||||
|
|
||||||
expected() : base_type() {}
|
expected()
|
||||||
|
: base_type() {}
|
||||||
|
|
||||||
~expected() = default;
|
~expected() = default;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user