Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 10 additions & 19 deletions llvm/include/llvm/ADT/STLExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -535,31 +535,22 @@ class filter_iterator_impl<WrappedIteratorT, PredicateT,

namespace detail {

template <bool is_bidirectional> struct fwd_or_bidi_tag_impl {
using type = std::forward_iterator_tag;
};

template <> struct fwd_or_bidi_tag_impl<true> {
using type = std::bidirectional_iterator_tag;
};

/// Helper which sets its type member to forward_iterator_tag if the category
/// of \p IterT does not derive from bidirectional_iterator_tag, and to
/// bidirectional_iterator_tag otherwise.
template <typename IterT> struct fwd_or_bidi_tag {
using type = typename fwd_or_bidi_tag_impl<std::is_base_of<
std::bidirectional_iterator_tag,
typename std::iterator_traits<IterT>::iterator_category>::value>::type;
};
/// A type alias which is std::bidirectional_iterator_tag if the category of
/// \p IterT derives from it, and std::forward_iterator_tag otherwise.
template <typename IterT>
using fwd_or_bidi_tag = std::conditional_t<
std::is_base_of_v<std::bidirectional_iterator_tag,
typename std::iterator_traits<IterT>::iterator_category>,
std::bidirectional_iterator_tag, std::forward_iterator_tag>;

} // namespace detail

/// Defines filter_iterator to a suitable specialization of
/// filter_iterator_impl, based on the underlying iterator's category.
template <typename WrappedIteratorT, typename PredicateT>
using filter_iterator = filter_iterator_impl<
WrappedIteratorT, PredicateT,
typename detail::fwd_or_bidi_tag<WrappedIteratorT>::type>;
using filter_iterator =
filter_iterator_impl<WrappedIteratorT, PredicateT,
detail::fwd_or_bidi_tag<WrappedIteratorT>>;

/// Convenience function that takes a range of elements and a predicate,
/// and return a new filter_iterator range.
Expand Down