Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Maybe<bool> #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Maybe.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

#include "Either.h"

// helper type used for a no-value Maybe
struct Nothing {};
Q_DECLARE_METATYPE(Nothing)

/** A simple option type implementation which represents the result
* of an operation which returned either a valid result or nothing.
*
Expand All @@ -23,7 +27,7 @@ class Maybe
* value.
*/
Maybe()
: m_value(false)
: m_value(Nothing())
{}

/** Returns true if this Maybe<T> has a value. */
Expand All @@ -50,7 +54,7 @@ class Maybe
: m_value(value)
{}

Either<bool,T> m_value;
Either<Nothing,T> m_value;
};

template <class T>
Expand Down