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

Fix Attribute copy/move constructors #1545

Merged
merged 3 commits into from
Nov 7, 2023

Conversation

franzpoeschel
Copy link
Contributor

Copy and move constructors of the Attribute class were accidentally custom-defined by having a constructor of the form:

    template <typename T>
    Attribute(T &&val);

Hence, be a bit more careful:

    template <typename T>
    Attribute(std::enable_if_t<
              // If T is `Attribute` or `Attribute const &`, this constructor
              // should not be used, but instead the move/copy constructors
              !std::is_same_v<
                  std::remove_cv_t<std::remove_reference_t<T>>,
                  Attribute>,
              T> &&val)

Comment on lines 113 to 116
!std::is_same_v<
std::remove_cv_t<std::remove_reference_t<T>>,
Attribute>,
T> &&val)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would specializing be simpler/cleaner than enable if?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might be better, yes. We would need to do this for every openPMD datatype then, though.
Probably best at that point to introduce something like the datatype macros that ADIOS2 has? openPMD_FOREACH_DATATYPE or so?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that needed? The specialization could be something like

template <typename T>
Attribute(Attribute<T> const &) = default;

template <typename T>
Attribute(Attribute<T> &&) = default;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Template specialization doesn't work in this case: With template, we cannot use default, without template, it's not a specialization, but an overload that is never chosen.
Using a specialization doesn't fix the underlying problem. In the current form, the constructor template <typename T> Attribute(T &&val) accepts anything, but is supposed to work only for all openPMD datatypes. That's a wrong interface.
Since the Intel Compiler doesn't understand this use of enable_if, I'd suggest using a macro.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The best would be a C++20 concept here though :D

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I propose is no template specialization but an overload for the constructors. Did you try if that works?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you did another approach with macros now ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I propose is no template specialization but an overload for the constructors. Did you try if that works?

That's exactly what this PR does. Just, it doesn't write all ~30 constructors explicitly, but uses a macro for that instead.

@ax3l ax3l self-assigned this Oct 24, 2023
@ax3l ax3l merged commit 9ad33b0 into openPMD:dev Nov 7, 2023
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants