This is an archive of the discontinued LLVM Phabricator instance.

Implement deduction guides for <unordered_set>
ClosedPublic

Authored by Quuxplusone on Feb 25 2019, 6:36 AM.

Details

Summary

In this case (alone) I needed to make allocator_type, hasher, and key_equal opaque to deduction using the __identity metafunction. With the original non-opaque aliases, some of the implicit deduction guides from unordered_set's constructors were interfering with deduction from the explicit deduction guides.

Specifically, if you leave typedef _Hash hasher alone:

test/std/containers/unord/unord.set/unord.set.cnstr/deduct.pass.cpp:180:24: note: in instantiation of member function 'std::__1::unordered_set<int, test_allocator<int>, std::__1::equal_to<int>, std::__1::allocator<int> >::unordered_set' requested here
    std::unordered_set s({ 1, 2, 1, INT_MAX, 3 }, 42, test_allocator<int>(0, 43));
                       ^

(Here we want to pick up the deduction guide for unordered_set(initializer_list, Size, Allocator) but it looks like overload resolution is preferring the guide implicitly generated from the constructor unordered_set(initializer_list, Size, Hash) instead. I think this might even be correct behavior according to the paper standard. I'll have to check with e.g. Mike Spertus about what's the intent of http://eel.is/c++draft/unord.req#18 "A deduction guide for an unordered associative container shall not participate in overload resolution if ... it has a Hash template parameter and an integral type or a type that qualifies as an allocator is deduced for that parameter." Namely, is this supposed to apply to just the explicit deduction guides, or the implicit ones as well?)

Diff Detail

Repository
rL LLVM

Event Timeline

Quuxplusone edited the summary of this revision. (Show Details)

Use ASSERT_SAME_TYPE. Add comments in deduct.fail.cpp. Rebase.

Use __iter_value_type<_InputIterator> instead of iterator_traits<_InputIterator>::value_type. @mclow.lists, I think this one is ready to land now, too.

Updated to use _EnableIf per EricWF's refactoring of June 23.

@mclow.lists ping! I still think this is ready to land.

ldionne accepted this revision.Jul 11 2019, 8:14 AM
This revision is now accepted and ready to land.Jul 11 2019, 8:14 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJul 11 2019, 8:16 AM

That bot is using Clang 6. r365923 adds an XFAIL for that compiler.