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 6e79786 commit 2f7e2f1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
36 changes: 20 additions & 16 deletions include/momo/stdish/set.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class set
typedef size_t size_type;
typedef ptrdiff_t difference_type;

typedef key_type value_type;
typedef momo::internal::Identity<key_type> value_type;
typedef key_compare value_compare;

typedef typename TreeSet::ConstIterator const_iterator;
Expand Down Expand Up @@ -714,58 +714,62 @@ class multiset : public set<TKey, TLessFunc, TAllocator, TTreeSet>
}
};

#ifdef MOMO_HAS_DEDUCTION_GUIDES

#define MOMO_DECLARE_DEDUCTION_GUIDES(set) \
template<typename Iterator, \
typename Key = typename std::iterator_traits<Iterator>::value_type, \
typename Allocator = std::allocator<Key>, \
typename = decltype(std::declval<Allocator&>().allocate(size_t{}))> \
typename = internal::ordered_checker<Key, Allocator>> \
set(Iterator, Iterator, Allocator = Allocator()) \
-> set<Key, std::less<Key>, Allocator>; \
template<typename Iterator, typename LessFunc, \
typename Key = typename std::iterator_traits<Iterator>::value_type, \
typename Allocator = std::allocator<Key>, \
typename = decltype(std::declval<LessFunc&>()(std::declval<const Key&>(), std::declval<const Key&>()))> \
typename = internal::ordered_checker<Key, Allocator, LessFunc>> \
set(Iterator, Iterator, LessFunc, Allocator = Allocator()) \
-> set<Key, LessFunc, Allocator>; \
template<typename Key, \
typename Allocator = std::allocator<Key>, \
typename = decltype(std::declval<Allocator&>().allocate(size_t{}))> \
typename = internal::ordered_checker<Key, Allocator>> \
set(std::initializer_list<Key>, Allocator = Allocator()) \
-> set<Key, std::less<Key>, Allocator>; \
template<typename Key, typename LessFunc, \
typename Allocator = std::allocator<Key>, \
typename = decltype(std::declval<LessFunc&>()(std::declval<const Key&>(), std::declval<const Key&>()))> \
typename = internal::ordered_checker<Key, Allocator, LessFunc>> \
set(std::initializer_list<Key>, LessFunc, Allocator = Allocator()) \
-> set<Key, LessFunc, Allocator>;

MOMO_DECLARE_DEDUCTION_GUIDES(set)
MOMO_DECLARE_DEDUCTION_GUIDES(multiset)

#undef MOMO_DECLARE_DEDUCTION_GUIDES

#ifdef MOMO_HAS_CONTAINERS_RANGES

#define MOMO_DECLARE_DEDUCTION_GUIDES_RANGES(set) \
template<std::ranges::input_range Range, \
typename Key = std::ranges::range_value_t<Range>, \
typename Allocator = std::allocator<Key>, \
typename = decltype(std::declval<Allocator&>().allocate(size_t{}))> \
typename = internal::ordered_checker<Key, Allocator>> \
set(std::from_range_t, Range&&, Allocator = Allocator()) \
-> set<Key, std::less<Key>, Allocator>; \
template<std::ranges::input_range Range, typename LessFunc, \
typename Key = std::ranges::range_value_t<Range>, \
typename Allocator = std::allocator<Key>, \
typename = decltype(std::declval<LessFunc&>()(std::declval<const Key&>(), std::declval<const Key&>())), \
typename = decltype(std::declval<Allocator&>().allocate(size_t{}))> \
typename = internal::ordered_checker<Key, Allocator, LessFunc>> \
set(std::from_range_t, Range&&, LessFunc, Allocator = Allocator()) \
-> set<Key, LessFunc, Allocator>;

#ifdef MOMO_HAS_DEDUCTION_GUIDES
MOMO_DECLARE_DEDUCTION_GUIDES(set)
MOMO_DECLARE_DEDUCTION_GUIDES(multiset)
#endif

#ifdef MOMO_HAS_CONTAINERS_RANGES
MOMO_DECLARE_DEDUCTION_GUIDES_RANGES(set)
MOMO_DECLARE_DEDUCTION_GUIDES_RANGES(multiset)
#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
9 changes: 9 additions & 0 deletions include/momo/stdish/set_map_utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,15 @@ namespace internal
class unordered_checker
{
};

template<typename Key, typename Allocator,
typename LessFunc = std::less<Key>,
typename = decltype(std::declval<Allocator&>().allocate(size_t{})),
typename = decltype(std::declval<LessFunc&>()(std::declval<const Key&>(),
std::declval<const Key&>()))>
class ordered_checker
{
};
#endif // MOMO_HAS_DEDUCTION_GUIDES
}

Expand Down
2 changes: 0 additions & 2 deletions test/sources/libcxx/set/set.cons/deduct.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,8 @@ int main(int, char **) {
}
#endif

#if MOMO_VERSION_MAJOR > 3
//AssociativeContainerDeductionGuidesSfinaeAway<std::set, std::set<int>>();
AssociativeContainerDeductionGuidesSfinaeAway<momo::stdish::set, momo::stdish::set<int>>();
#endif

return 0;
}

0 comments on commit 2f7e2f1

Please sign in to comment.