Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libcxx] contiguous iterator concept: don't require pointer or comple…
…te element types `contiguous_iterator` requires the iterator type passed is either a pointer type or that the element type of the iterator is a complete object type. These constraints are not part of the current wording in defining the `contiguous_iterator` concept - adjust the concept to reflect this. Inspired from discussion at https://reviews.llvm.org/D108645. Reviewed By: #libc, ldionne Differential Revision: https://reviews.llvm.org/D108855
- Loading branch information
Showing
3 changed files
with
59 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...uirements/iterator.concepts/iterator.concept.random.access/contiguous_iterator.verify.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
// REQUIRES: libc++ | ||
|
||
// This test checks that std::contiguous_iterator uses std::to_address, which is not SFINAE-friendly | ||
// when the type is missing the `T::element_type` typedef. | ||
|
||
#include <iterator> | ||
|
||
#include <compare> | ||
#include <cstddef> | ||
|
||
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; | ||
auto operator<=>(const self&) const = default; | ||
|
||
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; | ||
}; | ||
|
||
void test() { | ||
(void) std::contiguous_iterator<no_element_type>; | ||
// expected-error@*:* {{implicit instantiation of undefined template}} | ||
// expected-note@*:* {{to_address}} | ||
} |