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

Ensure implementation is up to spec #55

Open
wants to merge 43 commits into
base: main
Choose a base branch
from
Open

Ensure implementation is up to spec #55

wants to merge 43 commits into from

Conversation

wusatosi
Copy link
Member

@wusatosi wusatosi commented Jan 15, 2025

The goal of this PR is to add basic spec tests so the implementation would be minimally useable.

It would be fine to update the implementation itself in this branch.

See spec: https://eel.is/c++draft/inplace.vector

Meant to replace #46 which I accidentally broke.

cc: @jbab

@wusatosi wusatosi marked this pull request as draft January 15, 2025 22:25
{
for (auto &&__e : __x)
emplace_back(::std::move(__e));
}

constexpr inplace_vector &operator=(const inplace_vector &__x)
requires(__N == 0)
requires(__N == 0 || __iv_detail::__trivial_copy_assignment<__T>)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is it that for assignment you are using concepts (trivial_copy/move_assignment) while for the constructors you are using type traits (is_trivially_copy/move_constructible)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Its simply too much to write the full requirement here in-line.

I do think there should be a better name than __trivial_copy_assignment.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd argue it is less confusing if you list the individual requirements here. The difficulty finding a good name already indicates that __trivial_copy_assignment is not a good concept. Further disadvantages are:

  • You have to look up in a different place what the concept means
  • You have to get your head around why there is a concept in the first place. Is there something going on with assumption? How does this relate to the requirements from the specification?

It may be easier to write than you think:

  • You can leave out is_trivially_destructible, since is_trivially_copyable already implies that (https://en.cppreference.com/w/cpp/language/classes#Trivially_copyable_class). However, I would still write it to have an easily reviewable alignment with the specification.
  • You do not have to write a requires clause in the negative case at all. Overload resolution will always pick the more constrained version when it fits.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the comment, I do not know that overload resolution would pick the more constraint candidate, I will adopt your suggestion.

Copy link
Member Author

@wusatosi wusatosi Jan 16, 2025

Choose a reason for hiding this comment

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

I think I have to include the negation part, I am unable to compile without the negation, compiler complains ambiguous overload for 'operator='.

Copy link
Member Author

Choose a reason for hiding this comment

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

Suggestion adopted in 5b955bc

Comment on lines 1799 to 1832
#if 0

template <typename T> class InplaceVectorSMFs : public ::testing::Test {
public:
using IV = beman::inplace_vector::inplace_vector<T, 10>;
using IV0 = beman::inplace_vector::inplace_vector<T, 0>;

struct InputIterator {
using difference_type = std::ptrdiff_t;
using value_type = T;
using iterator_category = std::input_iterator_tag;

T step;
explicit constexpr InputIterator(T n) noexcept : step(n) {}
constexpr InputIterator &operator++() noexcept {
++step.value;
return *this;
}
constexpr InputIterator operator++(int) noexcept {
auto prev = *this;
++(*this);
return prev;
}
constexpr T operator*() const noexcept { return step; }
constexpr bool operator==(InputIterator const &) const noexcept = default;
};
static_assert(std::input_iterator<InputIterator>);
};

using AllTypes =
::testing::Types<Trivial, NonTriviallyDefaultConstructible,
NonTriviallyCopyConstructible,
NonTriviallyMoveConstructible, NonTriviallyCopyAssignable,
NonTriviallyMoveAssignable, TriviallyAssignable,
Copy link
Member Author

Choose a reason for hiding this comment

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

@jbab is there any update for this part of the test?

@wusatosi wusatosi marked this pull request as ready for review January 19, 2025 04:26
@wusatosi
Copy link
Member Author

The only thing left should be [sequence.reqmts]

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

Successfully merging this pull request may close these issues.

2 participants