Page MenuHomePhabricator

Implement the container bits of P0805R1
Needs ReviewPublic

Authored by mclow.lists on Feb 26 2018, 11:42 AM.

Details

Reviewers
EricWF
Summary

P0805R1 is about comparing heterogenous containers.

This is the implementation for array, vector, deque, list and forward_list.
The tuple bits will follow soon.

I hope to land this immediately after it is adopted in Jacksonville.

Diff Detail

Event Timeline

mclow.lists created this revision.Feb 26 2018, 11:42 AM

forgot to include the changes for <forward_list> in the diff.

Hmm, for vector and deque, we define a temporary variable, check that sizes match and then use range-and-a-half equal:

const typename vector<_Tp1, _Allocator1>::size_type __sz = __x.size();
return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());

For list we check that sizes match and then use range-and-a-half equal, but don't use a temporary variable:

return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());

For array we check that sizes match and then use dual-range equal:

if (_Size1 != _Size2)
    return false;
return _VSTD::equal(__x.begin(), __x.end(), __y.begin(), __y.end());

Is there a subtle reason for this inconsistency that I'm not seeing?

mclow.lists added a comment.EditedFeb 26 2018, 5:20 PM

Is there a subtle reason for this inconsistency that I'm not seeing?

I suspect that it's because they were written at different times.
(When I say 'written at different times', I mean I adapted the existing op== for the containers - not that this new code was written at different times)

I'm a fan of the four-legged bits, but in op== (except for forward_list we know the sizes are the same.

I can certainly make them all the same.

Add the tuple bits. Regularize the equality comparisons of the containers; i.e, don't try to be clever - let the compiler be clever.