Skip to content

Commit

Permalink
Merge pull request #133 from CaseyCarter/iter_cat_fixes
Browse files Browse the repository at this point in the history
Implement iterator_category per TS
  • Loading branch information
CaseyCarter authored Feb 11, 2018
2 parents ac8a7e6 + 0ca7305 commit 0841b66
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
16 changes: 9 additions & 7 deletions include/stl2/detail/iterator/concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,10 +458,13 @@ STL2_OPEN_NAMESPACE {

template <class> struct iterator_category {};

template <_IsNot<is_void> T>
struct iterator_category<T*> {
using type = ext::contiguous_iterator_tag;
};
template <class T>
struct iterator_category<T*>
: std::enable_if<std::is_object<T>::value, ext::contiguous_iterator_tag> {};

template <class T>
struct iterator_category<const T>
: iterator_category<T> {};

template <detail::MemberIteratorCategory T>
struct iterator_category<T> {
Expand All @@ -481,8 +484,7 @@ STL2_OPEN_NAMESPACE {
struct iterator_category<T> {};

template <class T>
using iterator_category_t =
meta::_t<iterator_category<remove_cv_t<T>>>;
using iterator_category_t = meta::_t<iterator_category<T>>;

///////////////////////////////////////////////////////////////////////////
// Iterator [iterators.iterator]
Expand Down Expand Up @@ -681,7 +683,7 @@ STL2_OPEN_NAMESPACE {
concept bool ContiguousIterator =
RandomAccessIterator<I> &&
DerivedFrom<iterator_category_t<I>, contiguous_iterator_tag> &&
_Is<reference_t<I>, is_lvalue_reference> &&
std::is_lvalue_reference<reference_t<I>>::value &&
Same<value_type_t<I>, __uncvref<reference_t<I>>>;
}

Expand Down
16 changes: 5 additions & 11 deletions include/stl2/detail/range/access.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,17 +501,15 @@ STL2_OPEN_NAMESPACE {
struct fn {
// Prefer member
template <class R>
requires
has_member<R>
requires has_member<R>
constexpr auto operator()(R& r) const
STL2_NOEXCEPT_RETURN(
r.data()
)

// Return begin(r) if it's a pointer
template <class R>
requires
!has_member<R> && has_pointer_iterator<R>
requires !has_member<R> && has_pointer_iterator<R>
constexpr auto operator()(R& r) const
STL2_NOEXCEPT_RETURN(
__stl2::begin(r)
Expand All @@ -520,9 +518,7 @@ STL2_OPEN_NAMESPACE {
// Extension: Support contiguous ranges with non-pointer
// iterators.
template <class R>
requires
!has_member<R> &&
!has_pointer_iterator<R> &&
requires !has_member<R> && !has_pointer_iterator<R> &&
has_contiguous_iterator<R>
constexpr auto operator()(R& r) const
noexcept(noexcept(__stl2::begin(r) == __stl2::end(r)
Expand All @@ -542,10 +538,8 @@ STL2_OPEN_NAMESPACE {

template <class R>
[[deprecated]] constexpr auto operator()(const R&& r) const
noexcept(noexcept(declval<const fn&>()(r)))
requires
has_member<const R> ||
has_pointer_iterator<const R> ||
noexcept(noexcept(std::declval<const fn&>()(r)))
requires has_member<const R> || has_pointer_iterator<const R> ||
has_contiguous_iterator<const R>
{
return (*this)(r);
Expand Down
3 changes: 0 additions & 3 deletions include/stl2/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,6 @@ STL2_OPEN_NAMESPACE {
__stl2::Common{T, U}
constexpr bool Common<T, U> = true;
}

template <typename T>
constexpr auto is_lvalue_reference_v = is_lvalue_reference<T>::value;
} STL2_CLOSE_NAMESPACE

#endif
2 changes: 2 additions & 0 deletions test/concepts/iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ namespace associated_type_test {
template <class T, bool B, class U>
using test = std::is_same<ns::iterator_category_t<iterator<T, B>>, U>;

CONCEPT_ASSERT(!meta::is_trait<ns::iterator_category<void*>>());
CONCEPT_ASSERT(!meta::is_trait<ns::iterator_category<int(*)()>>());
CONCEPT_ASSERT(!meta::is_trait<ns::iterator_category<iterator<std::output_iterator_tag, false>>>());
CONCEPT_ASSERT(!meta::is_trait<ns::iterator_category<iterator<std::output_iterator_tag, true>>>());

Expand Down

0 comments on commit 0841b66

Please sign in to comment.