Skip to content

Commit 5b940aa

Browse files
[ADT] Clean up fwd_or_bidi_tag with std::conditional_t (NFC)
fwd_or_bidi_tag selects one of two implementations of fwd_or_bidi_tag_impl depending on the condition. We can replace it with std::conditional_t, eliminating the need for helper structs fwd_or_bidi_tag_impl. This patch also converts the fwd_or_bidi_tag struct into an alias template, making "using filter_iterator" a little more readable.
1 parent 59d72b5 commit 5b940aa

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

llvm/include/llvm/ADT/STLExtras.h

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -535,31 +535,22 @@ class filter_iterator_impl<WrappedIteratorT, PredicateT,
535535

536536
namespace detail {
537537

538-
template <bool is_bidirectional> struct fwd_or_bidi_tag_impl {
539-
using type = std::forward_iterator_tag;
540-
};
541-
542-
template <> struct fwd_or_bidi_tag_impl<true> {
543-
using type = std::bidirectional_iterator_tag;
544-
};
545-
546-
/// Helper which sets its type member to forward_iterator_tag if the category
547-
/// of \p IterT does not derive from bidirectional_iterator_tag, and to
548-
/// bidirectional_iterator_tag otherwise.
549-
template <typename IterT> struct fwd_or_bidi_tag {
550-
using type = typename fwd_or_bidi_tag_impl<std::is_base_of<
551-
std::bidirectional_iterator_tag,
552-
typename std::iterator_traits<IterT>::iterator_category>::value>::type;
553-
};
538+
/// A type alias which is std::bidirectional_iterator_tag if the category of
539+
/// \p IterT derives from it, and std::forward_iterator_tag otherwise.
540+
template <typename IterT>
541+
using fwd_or_bidi_tag = std::conditional_t<
542+
std::is_base_of_v<std::bidirectional_iterator_tag,
543+
typename std::iterator_traits<IterT>::iterator_category>,
544+
std::bidirectional_iterator_tag, std::forward_iterator_tag>;
554545

555546
} // namespace detail
556547

557548
/// Defines filter_iterator to a suitable specialization of
558549
/// filter_iterator_impl, based on the underlying iterator's category.
559550
template <typename WrappedIteratorT, typename PredicateT>
560-
using filter_iterator = filter_iterator_impl<
561-
WrappedIteratorT, PredicateT,
562-
typename detail::fwd_or_bidi_tag<WrappedIteratorT>::type>;
551+
using filter_iterator =
552+
filter_iterator_impl<WrappedIteratorT, PredicateT,
553+
detail::fwd_or_bidi_tag<WrappedIteratorT>>;
563554

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

0 commit comments

Comments
 (0)