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

[SUGGESTION] Metafunction for rule of zero #665

Closed
JohelEGP opened this issue Sep 8, 2023 · 3 comments · Fixed by #808
Closed

[SUGGESTION] Metafunction for rule of zero #665

JohelEGP opened this issue Sep 8, 2023 · 3 comments · Fixed by #808

Comments

@JohelEGP
Copy link
Contributor

JohelEGP commented Sep 8, 2023

I first opened the "Discussions/Suggestions" #656.
But this is more of a mix of a bug report and suggestion.
I think it fits better in Issues.
PD: Linking between Issues and PRs, and from commits, is recorded,
but not to and from Discussions 👎.

The thread starting at #453 (comment)
demonstrates that it's not feasible to author Cpp2 types with the rule of zero.
You need either non-contextual knowledge of the members involved (so no luck with generic programming),
or attempt to simulate how the language does rule of zero, e.g.:

t: <A, B, C> type = {
  a: A = ();
  b: B = ();
  c: C = ();

  operator=: (out this) requires std::default_initializable<A>
                              && std::default_initializable<B>
                              && std::default_initializable<C> = { }
  operator=: (out this, that) requires std::copyable<A>
                                    && std::copyable<B>
                                    && std::copyable<C> = { }
  operator=: (out this, move that) requires std::movable<A>
                                         && std::movable<B>
                                         && std::movable<C> = { }
  operator=: (inout this, that) requires std::copy_assignable<A>
                                      && std::copy_assignable<B>
                                      && std::copy_assignable<C> = { }
  operator=: (inout this, move that) requires std::move_assignable<A>
                                           && std::move_assignable<B>
                                           && std::move_assignable<C> = { }
}

So I argue that we need a metafunction for the rule of zero.

For my current use case (implementation inheritance),
if I don't need to wrap any constructor,
I can just make it a @struct to employ the rule of zero.
Then I save myself having to apply #453 (comment).

Will your feature suggestion eliminate X% of security vulnerabilities of a given kind in current C++ code?
No.

Will your feature suggestion automate or eliminate X% of current C++ guidance literature?
No.
We take this for granted in Cpp1.
But Cpp2 has no general way of spelling it.

Describe alternatives you've considered.
The suggestion is to port to Cpp2 a feature Cpp1 has.
I can't think of an alternative spelling other than as a metafunction.

@JohelEGP
Copy link
Contributor Author

JohelEGP commented Sep 9, 2023

BTW, I was originally aware that this was better fit for Issues.
This is specially true for "suggestions" that would require the template to be filled.
But I felt pressured to use Discussions because a bunch of suggestions are being migrated over there.

@JohelEGP
Copy link
Contributor Author

JohelEGP commented Nov 4, 2023

This is the relevant guideline: C.20: If you can avoid defining default operations, do.

@JohelEGP
Copy link
Contributor Author

JohelEGP commented Nov 4, 2023

Simulating with requires only works if the type is templated (see #797 (comment)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant