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

Remove Mref #135

Closed
danakj opened this issue Dec 20, 2022 · 0 comments · Fixed by #141
Closed

Remove Mref #135

danakj opened this issue Dec 20, 2022 · 0 comments · Fixed by #141
Labels
design Design of the library systems as a whole, such as concepts

Comments

@danakj
Copy link
Collaborator

danakj commented Dec 20, 2022

I think it's a cool idea but the mref() annotation should be done through a static analysis check instead of in the type system.

By doing it in the type system, it forces function/method overloads when receiving const T& or T& in a template where the distinction matters. Overloading is against the principles. For example in Option:

  constexpr T& insert(T t) & noexcept
    requires(sus::mem::Move<T> &&
             !(std::is_reference_v<T> &&
               !std::is_const_v<std::remove_reference_t<T>>))
  {
    t_.set_some(move_to_storage(t));
    return t_.val_;
  }

  constexpr T& insert(Mref<std::remove_reference_t<T>> t) & noexcept
    requires(std::is_reference_v<T> &&
             !std::is_const_v<std::remove_reference_t<T>>)
  {
    t_.set_some(move_to_storage(t));
    return t_.val_;
  }

Keep mref()s

In anticipation of a static check, keep the mref() annotations that we have, but make it a function

template <class T>
decltype(auto) mref(T&& t) { return static_cast<T&&>(t); }
@danakj danakj added the design Design of the library systems as a whole, such as concepts label Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Design of the library systems as a whole, such as concepts
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant