Skip to content

Commit

Permalink
Update deduction guides
Browse files Browse the repository at this point in the history
  • Loading branch information
morzhovets committed Nov 9, 2024
1 parent a63c612 commit 3d05640
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 37 deletions.
68 changes: 41 additions & 27 deletions include/momo/stdish/unordered_multimap.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class unordered_multimap
typedef size_t size_type;
typedef ptrdiff_t difference_type;

typedef std::pair<const key_type, mapped_type> value_type;
typedef momo::internal::Identity<std::pair<const key_type, mapped_type>> value_type;

typedef momo::internal::HashDerivedIterator<typename HashMultiMap::Iterator,
momo::internal::MapReferenceStd> iterator;
Expand Down Expand Up @@ -840,78 +840,92 @@ class unordered_multimap_open : public unordered_multimap<TKey, TMapped, THashFu

#define MOMO_DECLARE_DEDUCTION_GUIDES(unordered_multimap) \
template<typename Iterator, \
typename Key = std::remove_const_t<typename std::iterator_traits<Iterator>::value_type::first_type>, \
typename Mapped = typename std::iterator_traits<Iterator>::value_type::second_type> \
typename Value = typename std::iterator_traits<Iterator>::value_type, \
typename Key = std::decay_t<typename Value::first_type>, \
typename Mapped = std::decay_t<typename Value::second_type>> \
unordered_multimap(Iterator, Iterator) \
-> unordered_multimap<Key, Mapped>; \
template<typename Iterator, \
typename Key = std::remove_const_t<typename std::iterator_traits<Iterator>::value_type::first_type>, \
typename Mapped = typename std::iterator_traits<Iterator>::value_type::second_type, \
typename Value = typename std::iterator_traits<Iterator>::value_type, \
typename Key = std::decay_t<typename Value::first_type>, \
typename Mapped = std::decay_t<typename Value::second_type>, \
typename Allocator = std::allocator<std::pair<const Key, Mapped>>, \
typename = decltype(std::declval<Allocator&>().allocate(size_t{}))> \
unordered_multimap(Iterator, Iterator, size_t, Allocator = Allocator()) \
-> unordered_multimap<Key, Mapped, HashCoder<Key>, std::equal_to<Key>, Allocator>; \
template<typename Iterator, typename HashFunc, \
typename Key = std::remove_const_t<typename std::iterator_traits<Iterator>::value_type::first_type>, \
typename Mapped = typename std::iterator_traits<Iterator>::value_type::second_type, \
typename Value = typename std::iterator_traits<Iterator>::value_type, \
typename Key = std::decay_t<typename Value::first_type>, \
typename Mapped = std::decay_t<typename Value::second_type>, \
typename Allocator = std::allocator<std::pair<const Key, Mapped>>, \
typename = decltype(std::declval<HashFunc&>()(std::declval<const Key&>())), \
typename = decltype(std::declval<Allocator&>().allocate(size_t{}))> \
unordered_multimap(Iterator, Iterator, size_t, HashFunc, Allocator = Allocator()) \
-> unordered_multimap<Key, Mapped, HashFunc, std::equal_to<Key>, Allocator>; \
template<typename Iterator, typename HashFunc, typename EqualFunc, \
typename Key = std::remove_const_t<typename std::iterator_traits<Iterator>::value_type::first_type>, \
typename Mapped = typename std::iterator_traits<Iterator>::value_type::second_type, \
typename Value = typename std::iterator_traits<Iterator>::value_type, \
typename Key = std::decay_t<typename Value::first_type>, \
typename Mapped = std::decay_t<typename Value::second_type>, \
typename Allocator = std::allocator<std::pair<const Key, Mapped>>, \
typename = decltype(std::declval<HashFunc&>()(std::declval<const Key&>())), \
typename = decltype(std::declval<EqualFunc&>()(std::declval<const Key&>(), std::declval<const Key&>()))> \
typename = decltype(std::declval<EqualFunc&>()(std::declval<const Key&>(), std::declval<const Key&>())), \
typename = decltype(std::declval<Allocator&>().allocate(size_t{}))> \
unordered_multimap(Iterator, Iterator, size_t, HashFunc, EqualFunc, Allocator = Allocator()) \
-> unordered_multimap<Key, Mapped, HashFunc, EqualFunc, Allocator>; \
template<typename Key, typename Mapped> \
unordered_multimap(std::initializer_list<std::pair<Key, Mapped>>) \
template<typename CKey, typename Mapped, \
typename Key = std::remove_const_t<CKey>> \
unordered_multimap(std::initializer_list<std::pair<CKey, Mapped>>) \
-> unordered_multimap<Key, Mapped>; \
template<typename Key, typename Mapped, \
template<typename CKey, typename Mapped, \
typename Key = std::remove_const_t<CKey>, \
typename Allocator = std::allocator<std::pair<const Key, Mapped>>, \
typename = decltype(std::declval<Allocator&>().allocate(size_t{}))> \
unordered_multimap(std::initializer_list<std::pair<Key, Mapped>>, size_t, Allocator = Allocator()) \
unordered_multimap(std::initializer_list<std::pair<CKey, Mapped>>, size_t, Allocator = Allocator()) \
-> unordered_multimap<Key, Mapped, HashCoder<Key>, std::equal_to<Key>, Allocator>; \
template<typename Key, typename Mapped, typename HashFunc, \
template<typename CKey, typename Mapped, typename HashFunc, \
typename Key = std::remove_const_t<CKey>, \
typename Allocator = std::allocator<std::pair<const Key, Mapped>>, \
typename = decltype(std::declval<HashFunc&>()(std::declval<const Key&>())), \
typename = decltype(std::declval<Allocator&>().allocate(size_t{}))> \
unordered_multimap(std::initializer_list<std::pair<Key, Mapped>>, size_t, HashFunc, Allocator = Allocator()) \
unordered_multimap(std::initializer_list<std::pair<CKey, Mapped>>, size_t, HashFunc, Allocator = Allocator()) \
-> unordered_multimap<Key, Mapped, HashFunc, std::equal_to<Key>, Allocator>; \
template<typename Key, typename Mapped, typename HashFunc, typename EqualFunc, \
template<typename CKey, typename Mapped, typename HashFunc, typename EqualFunc, \
typename Key = std::remove_const_t<CKey>, \
typename Allocator = std::allocator<std::pair<const Key, Mapped>>, \
typename = decltype(std::declval<HashFunc&>()(std::declval<const Key&>())), \
typename = decltype(std::declval<EqualFunc&>()(std::declval<const Key&>(), std::declval<const Key&>()))> \
unordered_multimap(std::initializer_list<std::pair<Key, Mapped>>, size_t, HashFunc, EqualFunc, Allocator = Allocator()) \
typename = decltype(std::declval<EqualFunc&>()(std::declval<const Key&>(), std::declval<const Key&>())), \
typename = decltype(std::declval<Allocator&>().allocate(size_t{}))> \
unordered_multimap(std::initializer_list<std::pair<CKey, Mapped>>, size_t, HashFunc, EqualFunc, Allocator = Allocator()) \
-> unordered_multimap<Key, Mapped, HashFunc, EqualFunc, Allocator>;

#define MOMO_DECLARE_DEDUCTION_GUIDES_RANGES(unordered_multimap) \
template<std::ranges::input_range Range, \
typename Key = std::remove_const_t<typename std::ranges::range_value_t<Range>::first_type>, \
typename Mapped = typename std::ranges::range_value_t<Range>::second_type> \
typename Value = std::ranges::range_value_t<Range>, \
typename Key = std::decay_t<typename Value::first_type>, \
typename Mapped = std::decay_t<typename Value::second_type>> \
unordered_multimap(std::from_range_t, Range&&) \
-> unordered_multimap<Key, Mapped>; \
template<std::ranges::input_range Range, \
typename Key = std::remove_const_t<typename std::ranges::range_value_t<Range>::first_type>, \
typename Mapped = typename std::ranges::range_value_t<Range>::second_type, \
typename Value = std::ranges::range_value_t<Range>, \
typename Key = std::decay_t<typename Value::first_type>, \
typename Mapped = std::decay_t<typename Value::second_type>, \
typename Allocator = std::allocator<std::pair<const Key, Mapped>>, \
typename = decltype(std::declval<Allocator&>().allocate(size_t{}))> \
unordered_multimap(std::from_range_t, Range&&, size_t, Allocator = Allocator()) \
-> unordered_multimap<Key, Mapped, HashCoder<Key>, std::equal_to<Key>, Allocator>; \
template<std::ranges::input_range Range, typename HashFunc, \
typename Key = std::remove_const_t<typename std::ranges::range_value_t<Range>::first_type>, \
typename Mapped = typename std::ranges::range_value_t<Range>::second_type, \
typename Value = std::ranges::range_value_t<Range>, \
typename Key = std::decay_t<typename Value::first_type>, \
typename Mapped = std::decay_t<typename Value::second_type>, \
typename Allocator = std::allocator<std::pair<const Key, Mapped>>, \
typename = decltype(std::declval<HashFunc&>()(std::declval<const Key&>())), \
typename = decltype(std::declval<Allocator&>().allocate(size_t{}))> \
unordered_multimap(std::from_range_t, Range&&, size_t, HashFunc, Allocator = Allocator()) \
-> unordered_multimap<Key, Mapped, HashFunc, std::equal_to<Key>, Allocator>; \
template<std::ranges::input_range Range, typename HashFunc, typename EqualFunc, \
typename Key = std::remove_const_t<typename std::ranges::range_value_t<Range>::first_type>, \
typename Mapped = typename std::ranges::range_value_t<Range>::second_type, \
typename Value = std::ranges::range_value_t<Range>, \
typename Key = std::decay_t<typename Value::first_type>, \
typename Mapped = std::decay_t<typename Value::second_type>, \
typename Allocator = std::allocator<std::pair<const Key, Mapped>>, \
typename = decltype(std::declval<HashFunc&>()(std::declval<const Key&>())), \
typename = decltype(std::declval<Allocator&>().allocate(size_t{})), \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,18 +217,14 @@ int main(int, char**)
assert(m.get_allocator().get_id() == 48);
}

#if !defined(TEST_GCC)
{
// Examples from LWG3025
momo::stdish::unordered_multimap m{std::pair{1, 1}, {2, 2}, {3, 3}};
ASSERT_SAME_TYPE(decltype(m), momo::stdish::unordered_multimap<int, int>);

#ifdef LIBCPP_HAS_BAD_NEWS_FOR_MOMO
momo::stdish::unordered_multimap m2{m.begin(), m.end()};
ASSERT_SAME_TYPE(decltype(m2), momo::stdish::unordered_multimap<int, int>);
#endif
}
#endif

{
// Examples from LWG3531
Expand Down Expand Up @@ -292,10 +288,8 @@ int main(int, char**)
}
#endif

#if MOMO_VERSION_MAJOR > 3
//UnorderedContainerDeductionGuidesSfinaeAway<std::unordered_multimap, std::unordered_multimap<int, long>>();
UnorderedContainerDeductionGuidesSfinaeAway<momo::stdish::unordered_multimap, momo::stdish::unordered_multimap<int, long>>();
#endif

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ int main(int, char**)
assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m)));
}

#if MOMO_VERSION_MAJOR > 3
{
momo::stdish::unordered_multimap m({ PC{1,1L}, PC{2,2L}, PC{1,1L}, PC{INT_MAX,1L}, PC{3,1L} }, 42, std::hash<long long>());
ASSERT_SAME_TYPE(decltype(m), momo::stdish::unordered_multimap<int, long, std::hash<long long>>);
Expand All @@ -126,7 +125,6 @@ int main(int, char**)
ASSERT_SAME_TYPE(decltype(m), momo::stdish::unordered_multimap<int, long, std::hash<long long>, std::equal_to<>>);
assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m)));
}
#endif

{
momo::stdish::unordered_multimap m({ PC{1,1L}, PC{2,2L}, PC{1,1L}, PC{INT_MAX,1L}, PC{3,1L} }, 42, std::hash<long long>(), std::equal_to<>(), test_allocator<PC>(0, 44));
Expand All @@ -151,7 +149,6 @@ int main(int, char**)
assert(m.get_allocator().get_id() == 46);
}

#if MOMO_VERSION_MAJOR > 3
{
momo::stdish::unordered_multimap m({ PC{1,1L}, PC{2,2L}, PC{1,1L}, PC{INT_MAX,1L}, PC{3,1L} }, 42, test_allocator<PC>(0, 47));
ASSERT_SAME_TYPE(decltype(m), momo::stdish::unordered_multimap<int, long, momo::HashCoder<int>, std::equal_to<int>, test_allocator<PC>>);
Expand All @@ -165,7 +162,6 @@ int main(int, char**)
assert(std::is_permutation(m.begin(), m.end(), std::begin(expected_m), std::end(expected_m)));
assert(m.get_allocator().get_id() == 48);
}
#endif

return 0;
}

0 comments on commit 3d05640

Please sign in to comment.