#include <ranges>
#include <cassert>
#include <concepts>
#include <utility>
#include "test_macros.h"
#include "test_iterators.h"
#include "types.h"
constexpr bool test() {
int buf[8] = {1, 2, 3, 4, 5, 6, 7, 8};
{
SizedRandomAccessView view{buf, buf + 8};
std::ranges::common_view<SizedRandomAccessView> common(view);
std::same_as<RandomAccessIter> auto end = common.end();
assert(base(end) == buf + 8);
}
{
SizedRandomAccessView view{buf, buf + 8};
std::ranges::common_view<SizedRandomAccessView> const common(view);
std::same_as<RandomAccessIter> auto end = common.end();
assert(base(end) == buf + 8);
}
return true;
}
int main(int, char**) {
test();
static_assert(test());
{
int buf[8] = {1, 2, 3, 4, 5, 6, 7, 8};
using CommonForwardIter = std::common_iterator<ForwardIter, sized_sentinel<ForwardIter>>;
using CommonIntIter = std::common_iterator<int*, sentinel_wrapper<int*>>;
{
SizedForwardView view{buf, buf + 8};
std::ranges::common_view<SizedForwardView> common(view);
std::same_as<CommonForwardIter> auto end = common.end();
assert(end == CommonForwardIter(std::ranges::end(view)));
}
{
CopyableView view{buf, buf + 8};
std::ranges::common_view<CopyableView> common(view);
std::same_as<CommonIntIter> auto end = common.end();
assert(end == CommonIntIter(std::ranges::end(view)));
}
{
SizedForwardView view{buf, buf + 8};
std::ranges::common_view<SizedForwardView> const common(view);
std::same_as<CommonForwardIter> auto end = common.end();
assert(end == CommonForwardIter(std::ranges::end(view)));
}
{
CopyableView view{buf, buf + 8};
std::ranges::common_view<CopyableView> const common(view);
std::same_as<CommonIntIter> auto end = common.end();
assert(end == CommonIntIter(std::ranges::end(view)));
}
}
return 0;
}