Skip to content

Commit

Permalink
Add simple check of nested typedefs in iterators deriving from a
Browse files Browse the repository at this point in the history
dependently-typed iterator_interface.
  • Loading branch information
tzlaine committed Feb 1, 2023
1 parent 8390819 commit a823593
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/random_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,50 @@ static_assert(
plus_eq<basic_random_access_iter, std::ptrdiff_t>::value,
"");

// This is here explicitly to check that the nested typedefs make it into the
// derived iterator type when boost::stl_interfaces::iterator_interface<...>
// is a dependent type.
template<typename ValueType>
struct basic_random_access_iter_dependent
: boost::stl_interfaces::iterator_interface<
basic_random_access_iter_dependent<ValueType>,
std::random_access_iterator_tag,
ValueType>
{
basic_random_access_iter_dependent() {}
basic_random_access_iter_dependent(ValueType * it) : it_(it) {}

ValueType & operator*() const { return *it_; }
basic_random_access_iter_dependent & operator+=(std::ptrdiff_t i)
{
it_ += i;
return *this;
}
friend std::ptrdiff_t operator-(
basic_random_access_iter_dependent lhs,
basic_random_access_iter_dependent rhs) noexcept
{
return lhs.it_ - rhs.it_;
}

private:
ValueType * it_;
};

using basic_random_access_iter_dependent_category =
basic_random_access_iter_dependent<int>::iterator_category;

BOOST_STL_INTERFACES_STATIC_ASSERT_CONCEPT(
basic_random_access_iter_dependent<int>, std::random_access_iterator)
BOOST_STL_INTERFACES_STATIC_ASSERT_ITERATOR_TRAITS(
basic_random_access_iter_dependent<int>,
std::random_access_iterator_tag,
std::random_access_iterator_tag,
int,
int &,
int *,
std::ptrdiff_t)

struct basic_adapted_random_access_iter
: boost::stl_interfaces::iterator_interface<
basic_adapted_random_access_iter,
Expand Down

0 comments on commit a823593

Please sign in to comment.