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

mch::var gets operators -> and * #33

Closed
wants to merge 1 commit into from
Closed
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
14 changes: 13 additions & 1 deletion code/mach7/patterns/primitive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ struct var : transparent_wrapper<T>
/// Helper conversion operator to let the variable be used in some places
/// where T was allowed
operator const result_type&() const noexcept { return base::value(); }

/// Helper operator to access the subobjects of the variable
const result_type* operator->() const noexcept { return &base::value(); }

/// Helper operator to access the subobjects of the variable
const result_type& operator*() const noexcept { return base::value(); }
};

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -380,7 +386,13 @@ struct var<T&>
/// \note If you get assertion here, it means you are trying to use the
/// value of this reference variable before it was bound (i.e. used
/// in pattern matching context to get its value).
operator const result_type&() const noexcept { XTL_ASSERT(m_value); return *m_value; }
operator T&() const noexcept { XTL_ASSERT(m_value); return *m_value; }

/// Helper operator to access the subobjects of the variable
T* operator->() const noexcept { XTL_ASSERT(m_value); return m_value; }

/// Helper operator to access the subobjects of the variable
T& operator*() const noexcept { XTL_ASSERT(m_value); return *m_value; }

/// Member that will hold matching value in case of successful matching
mutable T* m_value;
Expand Down