Skip to content

[SUGGESTION] Metafunction for rule of zero #665

Closed
@JohelEGP

Description

@JohelEGP

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions