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 10, 2024
1 parent 3d05640 commit 34e2e59
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 86 deletions.
62 changes: 36 additions & 26 deletions include/momo/stdish/unordered_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,22 @@ class unordered_map_open : public unordered_map<TKey, TMapped, THashFunc, TEqual
}
};

#ifdef MOMO_HAS_DEDUCTION_GUIDES

namespace internal
{
template<typename Key, typename Allocator,
typename HashFunc = HashCoder<Key>,
typename EqualFunc = std::equal_to<Key>,
typename = decltype(std::declval<Allocator&>().allocate(size_t{})),
typename = decltype(std::declval<HashFunc&>()(std::declval<const Key&>())),
typename = decltype(std::declval<EqualFunc&>()(std::declval<const Key&>(),
std::declval<const Key&>()))>
class unordered_map_checker
{
};
}

#define MOMO_DECLARE_DEDUCTION_GUIDES(unordered_map) \
template<typename Iterator, \
typename Value = typename std::iterator_traits<Iterator>::value_type, \
Expand All @@ -1092,26 +1108,23 @@ template<typename Iterator, \
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{}))> \
typename = internal::unordered_map_checker<Key, Allocator>> \
unordered_map(Iterator, Iterator, size_t, Allocator = Allocator()) \
-> unordered_map<Key, Mapped, HashCoder<Key>, std::equal_to<Key>, Allocator>; \
template<typename Iterator, typename HashFunc, \
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{}))> \
typename = internal::unordered_map_checker<Key, Allocator, HashFunc>> \
unordered_map(Iterator, Iterator, size_t, HashFunc, Allocator = Allocator()) \
-> unordered_map<Key, Mapped, HashFunc, std::equal_to<Key>, Allocator>; \
template<typename Iterator, typename HashFunc, typename EqualFunc, \
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<Allocator&>().allocate(size_t{}))> \
typename = internal::unordered_map_checker<Key, Allocator, HashFunc, EqualFunc>> \
unordered_map(Iterator, Iterator, size_t, HashFunc, EqualFunc, Allocator = Allocator()) \
-> unordered_map<Key, Mapped, HashFunc, EqualFunc, Allocator>; \
template<typename CKey, typename Mapped, \
Expand All @@ -1121,25 +1134,29 @@ unordered_map(std::initializer_list<std::pair<CKey, 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{}))> \
typename = internal::unordered_map_checker<Key, Allocator>> \
unordered_map(std::initializer_list<std::pair<CKey, Mapped>>, size_t, Allocator = Allocator()) \
-> unordered_map<Key, Mapped, HashCoder<Key>, std::equal_to<Key>, Allocator>; \
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{}))> \
typename = internal::unordered_map_checker<Key, Allocator, HashFunc>> \
unordered_map(std::initializer_list<std::pair<CKey, Mapped>>, size_t, HashFunc, Allocator = Allocator()) \
-> unordered_map<Key, Mapped, HashFunc, std::equal_to<Key>, Allocator>; \
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&>())), \
typename = decltype(std::declval<Allocator&>().allocate(size_t{}))> \
typename = internal::unordered_map_checker<Key, Allocator, HashFunc, EqualFunc>> \
unordered_map(std::initializer_list<std::pair<CKey, Mapped>>, size_t, HashFunc, EqualFunc, Allocator = Allocator()) \
-> unordered_map<Key, Mapped, HashFunc, EqualFunc, Allocator>;

MOMO_DECLARE_DEDUCTION_GUIDES(unordered_map)
MOMO_DECLARE_DEDUCTION_GUIDES(unordered_map_open)

#undef MOMO_DECLARE_DEDUCTION_GUIDES

#ifdef MOMO_HAS_CONTAINERS_RANGES

#define MOMO_DECLARE_DEDUCTION_GUIDES_RANGES(unordered_map) \
template<std::ranges::input_range Range, \
typename Value = std::ranges::range_value_t<Range>, \
Expand All @@ -1152,42 +1169,35 @@ template<std::ranges::input_range 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{}))> \
typename = internal::unordered_map_checker<Key, Allocator>> \
unordered_map(std::from_range_t, Range&&, size_t, Allocator = Allocator()) \
-> unordered_map<Key, Mapped, HashCoder<Key>, std::equal_to<Key>, Allocator>; \
template<std::ranges::input_range Range, typename HashFunc, \
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{}))> \
typename = internal::unordered_map_checker<Key, Allocator, HashFunc>> \
unordered_map(std::from_range_t, Range&&, size_t, HashFunc, Allocator = Allocator()) \
-> unordered_map<Key, Mapped, HashFunc, std::equal_to<Key>, Allocator>; \
template<std::ranges::input_range Range, typename HashFunc, typename EqualFunc, \
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{})), \
typename = decltype(std::declval<EqualFunc&>()(std::declval<const Key&>(), std::declval<const Key&>()))> \
typename = internal::unordered_map_checker<Key, Allocator, HashFunc, EqualFunc>> \
unordered_map(std::from_range_t, Range&&, size_t, HashFunc, EqualFunc, Allocator = Allocator()) \
-> unordered_map<Key, Mapped, HashFunc, EqualFunc, Allocator>;

#ifdef MOMO_HAS_DEDUCTION_GUIDES
MOMO_DECLARE_DEDUCTION_GUIDES(unordered_map)
MOMO_DECLARE_DEDUCTION_GUIDES(unordered_map_open)
#endif

#ifdef MOMO_HAS_CONTAINERS_RANGES
MOMO_DECLARE_DEDUCTION_GUIDES_RANGES(unordered_map)
MOMO_DECLARE_DEDUCTION_GUIDES_RANGES(unordered_map_open)
#endif

#undef MOMO_DECLARE_DEDUCTION_GUIDES
#undef MOMO_DECLARE_DEDUCTION_GUIDES_RANGES

#endif // MOMO_HAS_CONTAINERS_RANGES

#endif // MOMO_HAS_DEDUCTION_GUIDES

} // namespace stdish

} // namespace momo
Expand Down
62 changes: 36 additions & 26 deletions include/momo/stdish/unordered_multimap.h
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,22 @@ class unordered_multimap_open : public unordered_multimap<TKey, TMapped, THashFu
}
};

#ifdef MOMO_HAS_DEDUCTION_GUIDES

namespace internal
{
template<typename Key, typename Allocator,
typename HashFunc = HashCoder<Key>,
typename EqualFunc = std::equal_to<Key>,
typename = decltype(std::declval<Allocator&>().allocate(size_t{})),
typename = decltype(std::declval<HashFunc&>()(std::declval<const Key&>())),
typename = decltype(std::declval<EqualFunc&>()(std::declval<const Key&>(),
std::declval<const Key&>()))>
class unordered_multimap_checker
{
};
}

#define MOMO_DECLARE_DEDUCTION_GUIDES(unordered_multimap) \
template<typename Iterator, \
typename Value = typename std::iterator_traits<Iterator>::value_type, \
Expand All @@ -850,26 +866,23 @@ template<typename Iterator, \
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{}))> \
typename = internal::unordered_multimap_checker<Key, Allocator>> \
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 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{}))> \
typename = internal::unordered_multimap_checker<Key, Allocator, HashFunc>> \
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 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<Allocator&>().allocate(size_t{}))> \
typename = internal::unordered_multimap_checker<Key, Allocator, HashFunc, EqualFunc>> \
unordered_multimap(Iterator, Iterator, size_t, HashFunc, EqualFunc, Allocator = Allocator()) \
-> unordered_multimap<Key, Mapped, HashFunc, EqualFunc, Allocator>; \
template<typename CKey, typename Mapped, \
Expand All @@ -879,25 +892,29 @@ unordered_multimap(std::initializer_list<std::pair<CKey, 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{}))> \
typename = internal::unordered_multimap_checker<Key, 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 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{}))> \
typename = internal::unordered_multimap_checker<Key, Allocator, HashFunc>> \
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 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&>())), \
typename = decltype(std::declval<Allocator&>().allocate(size_t{}))> \
typename = internal::unordered_multimap_checker<Key, Allocator, HashFunc, EqualFunc>> \
unordered_multimap(std::initializer_list<std::pair<CKey, Mapped>>, size_t, HashFunc, EqualFunc, Allocator = Allocator()) \
-> unordered_multimap<Key, Mapped, HashFunc, EqualFunc, Allocator>;

MOMO_DECLARE_DEDUCTION_GUIDES(unordered_multimap)
MOMO_DECLARE_DEDUCTION_GUIDES(unordered_multimap_open)

#undef MOMO_DECLARE_DEDUCTION_GUIDES

#ifdef MOMO_HAS_CONTAINERS_RANGES

#define MOMO_DECLARE_DEDUCTION_GUIDES_RANGES(unordered_multimap) \
template<std::ranges::input_range Range, \
typename Value = std::ranges::range_value_t<Range>, \
Expand All @@ -910,42 +927,35 @@ template<std::ranges::input_range 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{}))> \
typename = internal::unordered_multimap_checker<Key, Allocator>> \
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 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{}))> \
typename = internal::unordered_multimap_checker<Key, Allocator, HashFunc>> \
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 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{})), \
typename = decltype(std::declval<EqualFunc&>()(std::declval<const Key&>(), std::declval<const Key&>()))> \
typename = internal::unordered_multimap_checker<Key, Allocator, HashFunc, EqualFunc>> \
unordered_multimap(std::from_range_t, Range&&, size_t, HashFunc, EqualFunc, Allocator = Allocator()) \
-> unordered_multimap<Key, Mapped, HashFunc, EqualFunc, Allocator>;

#ifdef MOMO_HAS_DEDUCTION_GUIDES
MOMO_DECLARE_DEDUCTION_GUIDES(unordered_multimap)
MOMO_DECLARE_DEDUCTION_GUIDES(unordered_multimap_open)
#endif

#ifdef MOMO_HAS_CONTAINERS_RANGES
MOMO_DECLARE_DEDUCTION_GUIDES_RANGES(unordered_multimap)
MOMO_DECLARE_DEDUCTION_GUIDES_RANGES(unordered_multimap_open)
#endif

#undef MOMO_DECLARE_DEDUCTION_GUIDES
#undef MOMO_DECLARE_DEDUCTION_GUIDES_RANGES

#endif // MOMO_HAS_CONTAINERS_RANGES

#endif // MOMO_HAS_DEDUCTION_GUIDES

} // namespace stdish

} // namespace momo
Expand Down
Loading

0 comments on commit 34e2e59

Please sign in to comment.