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

Allow making sets and maps with move-only keys and/or values #4982

Open
wants to merge 6 commits into
base: trunk
Choose a base branch
from

Conversation

danakj
Copy link
Contributor

@danakj danakj commented Feb 20, 2025

When the key or value is move-only, then the set or map will be as well.

@danakj
Copy link
Contributor Author

danakj commented Feb 20, 2025

We have a type (FacetTypeInfo) that we never want to copy (#4920), because it does the wrong thing. It's in a hash container however, so it breaks compile due to being move-only right now. Thoughts?

@danakj
Copy link
Contributor Author

danakj commented Feb 20, 2025

Hm this looks like a clang-16 compiler issue; it builds with clang 17.0.6

When the key or value is move-only, then the set or map will be as well.
@danakj
Copy link
Contributor Author

danakj commented Feb 20, 2025

Hm this looks like a clang-16 compiler issue; it builds with clang 17.0.6

Yeah it's a bug in std::pair comparison in clang-16. I def recall seeing this before. I added a workaround for clang-16 only.

@danakj
Copy link
Contributor Author

danakj commented Feb 20, 2025

We have a type (FacetTypeInfo) that we never want to copy (#4920), because it does the wrong thing. It's in a hash container however, so it breaks compile due to being move-only right now. Thoughts?

I am removing the 'should not be copied' property of that type in #4989 but maybe we'd want these things to work with move-only types in the future still?

Comment on lines 62 to 69
template <typename SetT>
class CopyableSetTest : public ::testing::Test {};

using Types =
::testing::Types<Set<int>, Set<int, 16>, Set<int, 128>, Set<TestData>,
Set<TestData, 16>, Set<MoveOnlyTestData>,
Set<MoveOnlyTestData, 16>>;
TYPED_TEST_SUITE(SetTest, Types);
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about having a small / narrow test for move-only types and the restricted map API? I feel like that would let us avoid having the complexity of handling move-only types and skipping some of the tests in the suite below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I think that would be okay, done.

Comment on lines 17 to 27
// Workaround for std::pair comparison deficiency in clang-16.
#if defined(__clang_major__) && __clang_major__ <= 16
namespace std {
template <class T, class U, class V, class W>
requires(convertible_to<V, T> && convertible_to<W, U>)
inline auto operator==(pair<T&, U&> lhs, pair<V, W> rhs) -> bool {
return lhs.first == static_cast<T>(rhs.first) &&
lhs.second == static_cast<U>(rhs.second);
}
} // namespace std
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be keyed on libc++ versions rather than Clang versions?

This is ... a pretty rough workaround...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, using _LIBCPP_VERSION now

@chandlerc
Copy link
Contributor

We have a type (FacetTypeInfo) that we never want to copy (#4920), because it does the wrong thing. It's in a hash container however, so it breaks compile due to being move-only right now. Thoughts?

I am removing the 'should not be copied' property of that type in #4989 but maybe we'd want these things to work with move-only types in the future still?

Realizing I didn't make that clear -- yeah, I think supporting move only types is a good thing, so happy with the direction here.

Copy link
Contributor Author

@danakj danakj left a comment

Choose a reason for hiding this comment

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

PTAL

Comment on lines 17 to 27
// Workaround for std::pair comparison deficiency in clang-16.
#if defined(__clang_major__) && __clang_major__ <= 16
namespace std {
template <class T, class U, class V, class W>
requires(convertible_to<V, T> && convertible_to<W, U>)
inline auto operator==(pair<T&, U&> lhs, pair<V, W> rhs) -> bool {
return lhs.first == static_cast<T>(rhs.first) &&
lhs.second == static_cast<U>(rhs.second);
}
} // namespace std
#endif
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, using _LIBCPP_VERSION now

Comment on lines 62 to 69
template <typename SetT>
class CopyableSetTest : public ::testing::Test {};

using Types =
::testing::Types<Set<int>, Set<int, 16>, Set<int, 128>, Set<TestData>,
Set<TestData, 16>, Set<MoveOnlyTestData>,
Set<MoveOnlyTestData, 16>>;
TYPED_TEST_SUITE(SetTest, Types);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I think that would be okay, done.

@danakj danakj requested a review from chandlerc February 21, 2025 14:57
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