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

Improved constructor tests #60

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Improved constructor tests #60

wants to merge 1 commit into from

Conversation

jbab
Copy link
Collaborator

@jbab jbab commented Jan 30, 2025

No description provided.

if (std::is_same_v<T, NonTriviallyDefaultConstructible> ||
std::is_same_v<T, NonTrivial>) {
if constexpr (std::is_scalar_v<T> || std::is_aggregate_v<T> ||
!std::is_trivially_default_constructible_v<T>) {

This comment was marked as resolved.

Copy link
Member

Choose a reason for hiding this comment

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

ops, didnt see the negation.

Copy link
Member

Choose a reason for hiding this comment

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

I am not sure if this is actually better than std::is_same_v<T, NonTriviallyDefaultConstructible> || std::is_same_v<T, NonTrivial>, we can do the comparison here not because the underlying is a scalar or an aggregate, it is because we know it has a well defined value-initialization.

Comment on lines +87 to +103
using T = TestFixture::T;
using InputIterator = TestFixture::InputIterator;

IV a(InputIterator{0}, InputIterator{IV::max_size() / 2});
EXPECT_EQ(a.size(), IV::max_size() / 2);
if (!a.empty()) {
EXPECT_EQ(a.back().value, IV::max_size() / 2 - 1);
for (std::size_t n : {std::size_t(0), IV::max_size() / 2u, IV::max_size()}) {
// InputIterator
InputIterator::num_deref = 0u;
IV a(InputIterator{}, InputIterator{static_cast<int>(n)});
EXPECT_EQ(a.size(), n);
for (int i = 0; i < static_cast<int>(n); ++i) {
EXPECT_EQ(a[i], T{i});
}
// Only single-pass through input range
EXPECT_EQ(InputIterator::num_deref, n);

// RandomAccessIterator
IV b(a.begin(), a.end());
EXPECT_EQ(b, a);
Copy link
Member

Choose a reason for hiding this comment

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

This is really helpful, thanks!

Copy link
Member

@DeveloperPaul123 DeveloperPaul123 left a comment

Choose a reason for hiding this comment

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

Looks good to me! Nice work 👍

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.

3 participants