Differential D101396 Diff 344185 libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.random.access/contiguous_iterator.compile.pass.cpp
Changeset View
Changeset View
Standalone View
Standalone View
libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.random.access/contiguous_iterator.compile.pass.cpp
- This file was added.
//===----------------------------------------------------------------------===// | |||||
// | |||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | |||||
// See https://llvm.org/LICENSE.txt for license information. | |||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | |||||
// | |||||
//===----------------------------------------------------------------------===// | |||||
// UNSUPPORTED: c++03, c++11, c++14, c++17 | |||||
// UNSUPPORTED: libcpp-no-concepts | |||||
// UNSUPPORTED: gcc-10 | |||||
// template<class T> | |||||
// concept random_access_iterator; | |||||
Quuxplusone: concept contiguous_iterator; | |||||
#include <iterator> | |||||
#include "test_iterators.h" | |||||
static_assert(!std::contiguous_iterator<input_iterator<int*> >); | |||||
static_assert(!std::contiguous_iterator<forward_iterator<int*> >); | |||||
static_assert(!std::contiguous_iterator<bidirectional_iterator<int*> >); | |||||
static_assert(!std::contiguous_iterator<random_access_iterator<int*> >); | |||||
static_assert(std::contiguous_iterator<contiguous_iterator<int*> >); | |||||
static_assert(std::contiguous_iterator<int*>); | |||||
static_assert(std::contiguous_iterator<int const*>); | |||||
static_assert(std::contiguous_iterator<int volatile*>); | |||||
static_assert(std::contiguous_iterator<int const volatile*>); | |||||
struct simple_contiguous_iterator { | |||||
typedef std::contiguous_iterator_tag iterator_category; | |||||
Not Done ReplyInline ActionsMost importantly, please check the test iterators from test_iterators.h — e.g. static_assert(std::contiguous_iterator<contiguous_iterator<int*>>); Any test iterators that don't match the concepts will want to be fixed. Quuxplusone: Most importantly, please check the test iterators from `test_iterators.h` — e.g.
```… | |||||
I have those a few lines above: static_assert(!std::contiguous_iterator<input_iterator<int*> >); static_assert(!std::contiguous_iterator<forward_iterator<int*> >); static_assert(!std::contiguous_iterator<bidirectional_iterator<int*> >); static_assert(!std::contiguous_iterator<random_access_iterator<int*> >); static_assert(std::contiguous_iterator<contiguous_iterator<int*> >); zoecarver: I have those a few lines above:
```
static_assert(!std… | |||||
typedef int value_type; | |||||
typedef int element_type; | |||||
typedef std::ptrdiff_t difference_type; | |||||
typedef int* pointer; | |||||
typedef int& reference; | |||||
typedef simple_contiguous_iterator self; | |||||
simple_contiguous_iterator(); | |||||
reference operator*() const; | |||||
pointer operator->() const; | |||||
friend bool operator==(const self, const self y); | |||||
friend bool operator< (const self, const self y); | |||||
friend bool operator<=(const self, const self y); | |||||
friend bool operator> (const self, const self y); | |||||
friend bool operator>=(const self, const self y); | |||||
self& operator++(); | |||||
Not Done ReplyInline Actions(A) this could be operator<=>? Quuxplusone: (A) this could be `operator<=>`?
(B) pass-by-const-value alert! I think you wanted pass-by… | |||||
self operator++(int); | |||||
self& operator--(); | |||||
self operator--(int); | |||||
self& operator+=(difference_type n); | |||||
self operator+(difference_type n) const; | |||||
friend self operator+(difference_type n, self x); | |||||
self& operator-=(difference_type n); | |||||
self operator-(difference_type n) const; | |||||
difference_type operator-(const self n) const; | |||||
reference operator[](difference_type n) const; | |||||
}; | |||||
static_assert(std::random_access_iterator<simple_contiguous_iterator>); | |||||
static_assert(std::contiguous_iterator<simple_contiguous_iterator>); | |||||
struct missmatch_value_iter_ref_t { | |||||
typedef std::contiguous_iterator_tag iterator_category; | |||||
typedef short value_type; | |||||
typedef std::ptrdiff_t difference_type; | |||||
typedef int* pointer; | |||||
typedef int& reference; | |||||
typedef missmatch_value_iter_ref_t self; | |||||
missmatch_value_iter_ref_t(); | |||||
reference operator*() const; | |||||
pointer operator->() const; | |||||
friend bool operator==(const self, const self y); | |||||
friend bool operator< (const self, const self y); | |||||
friend bool operator<=(const self, const self y); | |||||
friend bool operator> (const self, const self y); | |||||
friend bool operator>=(const self, const self y); | |||||
self& operator++(); | |||||
self operator++(int); | |||||
self& operator--(); | |||||
self operator--(int); | |||||
self& operator+=(difference_type n); | |||||
self operator+(difference_type n) const; | |||||
friend self operator+(difference_type n, self x); | |||||
self& operator-=(difference_type n); | |||||
self operator-(difference_type n) const; | |||||
difference_type operator-(const self n) const; | |||||
reference operator[](difference_type n) const; | |||||
}; | |||||
static_assert(std::random_access_iterator<missmatch_value_iter_ref_t>); | |||||
static_assert(!std::contiguous_iterator<missmatch_value_iter_ref_t>); | |||||
struct wrong_iter_reference_t { | |||||
typedef std::contiguous_iterator_tag iterator_category; | |||||
typedef short value_type; | |||||
typedef std::ptrdiff_t difference_type; | |||||
typedef int* pointer; | |||||
typedef short& reference; | |||||
typedef wrong_iter_reference_t self; | |||||
wrong_iter_reference_t(); | |||||
reference operator*() const; | |||||
pointer operator->() const; | |||||
friend bool operator==(const self, const self y); | |||||
friend bool operator< (const self, const self y); | |||||
friend bool operator<=(const self, const self y); | |||||
friend bool operator> (const self, const self y); | |||||
friend bool operator>=(const self, const self y); | |||||
self& operator++(); | |||||
self operator++(int); | |||||
self& operator--(); | |||||
self operator--(int); | |||||
self& operator+=(difference_type n); | |||||
self operator+(difference_type n) const; | |||||
friend self operator+(difference_type n, self x); | |||||
self& operator-=(difference_type n); | |||||
self operator-(difference_type n) const; | |||||
difference_type operator-(const self n) const; | |||||
reference operator[](difference_type n) const; | |||||
}; | |||||
static_assert(std::random_access_iterator<wrong_iter_reference_t>); | |||||
static_assert(!std::contiguous_iterator<wrong_iter_reference_t>); | |||||
struct no_element_type { | |||||
typedef std::contiguous_iterator_tag iterator_category; | |||||
typedef int value_type; | |||||
typedef std::ptrdiff_t difference_type; | |||||
typedef int* pointer; | |||||
typedef int& reference; | |||||
typedef no_element_type self; | |||||
no_element_type(); | |||||
reference operator*() const; | |||||
pointer operator->() const; | |||||
friend bool operator==(const self, const self y); | |||||
friend bool operator< (const self, const self y); | |||||
friend bool operator<=(const self, const self y); | |||||
friend bool operator> (const self, const self y); | |||||
friend bool operator>=(const self, const self y); | |||||
self& operator++(); | |||||
self operator++(int); | |||||
self& operator--(); | |||||
self operator--(int); | |||||
self& operator+=(difference_type n); | |||||
self operator+(difference_type n) const; | |||||
friend self operator+(difference_type n, self x); | |||||
self& operator-=(difference_type n); | |||||
self operator-(difference_type n) const; | |||||
difference_type operator-(const self n) const; | |||||
reference operator[](difference_type n) const; | |||||
}; | |||||
static_assert(std::random_access_iterator<no_element_type>); | |||||
static_assert(!std::contiguous_iterator<no_element_type>); | |||||
struct to_address_wrong_return_type { | |||||
typedef std::contiguous_iterator_tag iterator_category; | |||||
typedef int value_type; | |||||
typedef int element_type; | |||||
typedef std::ptrdiff_t difference_type; | |||||
typedef int* pointer; | |||||
typedef int& reference; | |||||
typedef to_address_wrong_return_type self; | |||||
to_address_wrong_return_type(); | |||||
reference operator*() const; | |||||
pointer operator->() const; | |||||
friend bool operator==(const self, const self y); | |||||
friend bool operator< (const self, const self y); | |||||
friend bool operator<=(const self, const self y); | |||||
friend bool operator> (const self, const self y); | |||||
friend bool operator>=(const self, const self y); | |||||
self& operator++(); | |||||
self operator++(int); | |||||
self& operator--(); | |||||
self operator--(int); | |||||
self& operator+=(difference_type n); | |||||
self operator+(difference_type n) const; | |||||
friend self operator+(difference_type n, self x); | |||||
self& operator-=(difference_type n); | |||||
self operator-(difference_type n) const; | |||||
difference_type operator-(const self n) const; | |||||
reference operator[](difference_type n) const; | |||||
}; | |||||
template<> | |||||
struct std::pointer_traits<to_address_wrong_return_type> { | |||||
typedef void element_type; | |||||
void *to_address(to_address_wrong_return_type const&); | |||||
}; | |||||
static_assert(std::random_access_iterator<to_address_wrong_return_type>); | |||||
static_assert(!std::contiguous_iterator<to_address_wrong_return_type>); | |||||
template<class> | |||||
struct template_and_no_element_type { | |||||
typedef std::contiguous_iterator_tag iterator_category; | |||||
typedef int value_type; | |||||
typedef std::ptrdiff_t difference_type; | |||||
typedef int* pointer; | |||||
typedef int& reference; | |||||
typedef template_and_no_element_type self; | |||||
template_and_no_element_type(); | |||||
reference operator*() const; | |||||
pointer operator->() const; | |||||
friend bool operator==(const self, const self y); | |||||
friend bool operator< (const self, const self y); | |||||
friend bool operator<=(const self, const self y); | |||||
friend bool operator> (const self, const self y); | |||||
friend bool operator>=(const self, const self y); | |||||
self& operator++(); | |||||
self operator++(int); | |||||
self& operator--(); | |||||
self operator--(int); | |||||
self& operator+=(difference_type n); | |||||
self operator+(difference_type n) const; | |||||
friend self operator+(difference_type n, self x); | |||||
self& operator-=(difference_type n); | |||||
self operator-(difference_type n) const; | |||||
difference_type operator-(const self n) const; | |||||
reference operator[](difference_type n) const; | |||||
}; | |||||
// Template param is used instead of element_type. | |||||
static_assert(std::random_access_iterator<template_and_no_element_type<int>>); | |||||
static_assert(std::contiguous_iterator<template_and_no_element_type<int>>); |
concept contiguous_iterator;