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

Provide Tuple::as_ref and as_mut #421

Open
danakj opened this issue Dec 6, 2023 · 0 comments
Open

Provide Tuple::as_ref and as_mut #421

danakj opened this issue Dec 6, 2023 · 0 comments
Labels
design Design of the library systems as a whole, such as concepts

Comments

@danakj
Copy link
Collaborator

danakj commented Dec 6, 2023

Rust does not have this ability due to lack of variadics, though the tuple_list crate has something: https://docs.rs/tuple_list/latest/tuple_list/trait.AsTupleOfRefs.html

  constexpr auto as() const& {
    return [this]<size_t... Is>(std::index_sequence<Is...>) {
      return ::sus::Tuple<const std::remove_reference_t<Ts>&...>(
          tuple_.template at<Is>()...);
    }(std::make_index_sequence<sizeof...(Ts)>());
  }
  constexpr auto as_mut() & {
    return [this]<size_t... Is>(std::index_sequence<Is...>) {
      return ::sus::Tuple<Ts&...>(tuple_.template at_mut<Is>()...);
    }(std::make_index_sequence<sizeof...(Ts)>());
  }

These methods of Choice should be able to be implemented as just tuple_.as_ref() or tuple_.as_mut().

@danakj danakj added the design Design of the library systems as a whole, such as concepts label Dec 6, 2023
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

No branches or pull requests

1 participant