Skip to content

Conversation

Quuxplusone
Copy link
Contributor

Just like the standard std::partition algorithm, this member function
reorders the slot_map's elements in such a way that all elements for which
the predicate pred returns true precede the elements for which pred
returns false. The relative order of the elements is not preserved.

The function returns an iterator to the first element of the second group
(which may be end(), in the case that all elements belong to the first group).

Addresses part of #131, although I'm not sure whether this really addresses
whatever use case @p-groarke is thinking of.

Just like the standard `std::partition` algorithm, this member function
reorders the slot_map's elements in such a way that all elements for which
the predicate `pred` returns `true` precede the elements for which `pred`
returns `false`. The relative order of the elements is not preserved.

The function returns an iterator to the first element of the second group
(which may be `end()`, in the case that all elements belong to the first group).

Addresses part of WG21-SG14#131, although I'm not sure whether this really addresses
whatever use case @p-groarke is thinking of.
@p-groarke
Copy link

p-groarke commented Jan 18, 2019

TBH, I'm not sure this is need. std::partition has worked great for my use cases so far.

@Quuxplusone
Copy link
Contributor Author

TBH, I'm not sure this is need. std::partition has worked great for my use cases so far.

That would be great, but off the top of my head, would std::partition do the wrong thing because it would break the association between elements and keys? I mean https://wandbox.org/permlink/NdHnBhZgooDn0raP

stdext::slot_map<int> sm;
auto k1 = sm.insert(1);
auto k2 = sm.insert(2);
assert(sm.at(k1) == 1);
assert(sm.at(k2) == 2);
std::partition(sm.begin(), sm.end(), [](int x) { return x == 2; });
assert(sm.at(k1) == 2);
assert(sm.at(k2) == 1);

@p-groarke
Copy link

p-groarke commented Jan 18, 2019

Oh yes your right, that's why we needed this. Sorry, been a long time :)

return 1;
}

constexpr void underlying_swap(const_iterator cit, const_iterator cjt) {

Choose a reason for hiding this comment

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

Comment and complexity would be nice to conform to the rest of the header.

}

template<class Pred>
constexpr iterator partition(const Pred& pred) {

Choose a reason for hiding this comment

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

Comments and complexity would be welcome.

@p-groarke
Copy link

@Quuxplusone Please take a look at #147
I discuss some issues I see in slot_map which would affect this PR. Cheers

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