-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libc++][ranges] LWG4001: iota_view
should provide empty
#79687
Changes from 5 commits
fe76be2
bdb67fc
b76e34c
02c4e71
d769525
8b1131f
40fa938
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
|
||
// constexpr bool empty() const; | ||
|
||
#include <cassert> | ||
#include <concepts> | ||
#include <ranges> | ||
#include <utility> | ||
#include <vector> | ||
|
||
#include "types.h" | ||
|
||
template <typename R> | ||
concept HasEmpty = requires(R r) { | ||
std::ranges::empty(r); | ||
{ r.empty() } -> std::same_as<bool>; | ||
}; | ||
|
||
H-G-Hristov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
constexpr void test_empty_iota_sfinae() { | ||
std::vector<int> ev; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: what do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Normally I prefer long descriptive names but the libc++ tests use short names, so I try to be consistent: I can change these. |
||
|
||
// Both parameters are non-const | ||
{ | ||
auto iv = std::views::iota(std::ranges::begin(ev), std::ranges::end(ev)); | ||
|
||
static_assert(HasEmpty<decltype(iv)>); | ||
} | ||
// Left parameter is const | ||
{ | ||
auto iv = std::views::iota(std::ranges::begin(std::as_const(ev)), std::ranges::end(ev)); | ||
|
||
static_assert(HasEmpty<decltype(iv)>); | ||
} | ||
// Right parameter is const | ||
{ | ||
auto iv = std::views::iota(std::ranges::begin(ev), std::ranges::end(std::as_const(ev))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: does using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought it was good to be detailed. Should I remove those? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed |
||
|
||
static_assert(HasEmpty<decltype(iv)>); | ||
} | ||
// Both parameters are const | ||
{ | ||
auto iv = std::views::iota(std::ranges::begin(std::as_const(ev)), std::ranges::end(std::as_const(ev))); | ||
|
||
static_assert(HasEmpty<decltype(iv)>); | ||
} | ||
} | ||
|
||
constexpr void test_nonempty_iota_sfinae() { | ||
// Default ctr | ||
{ | ||
std::ranges::iota_view<Int42<DefaultTo42>> iv; | ||
|
||
static_assert(HasEmpty<decltype(iv)>); | ||
} | ||
// Value pass | ||
{ | ||
std::ranges::iota_view<SomeInt> iv(SomeInt(94)); | ||
|
||
static_assert(HasEmpty<decltype(iv)>); | ||
} | ||
|
||
{ | ||
std::vector<char> v; | ||
auto it = std::back_inserter(v); | ||
auto iv = std::views::iota(it); | ||
|
||
static_assert(HasEmpty<decltype(iv)>); | ||
} | ||
{ | ||
std::vector<char> v{'b', 'a', 'b', 'a', 'z', 'm', 't'}; | ||
auto it = std::back_inserter(v); | ||
auto iv = std::views::iota(it); | ||
|
||
static_assert(HasEmpty<decltype(iv)>); | ||
} | ||
} | ||
|
||
constexpr void test_empty_iota() { | ||
std::vector<int> ev; | ||
|
||
// Both parameters are non-const | ||
{ | ||
auto iv = std::views::iota(std::ranges::begin(ev), std::ranges::end(ev)); | ||
|
||
assert(iv.empty()); | ||
} | ||
// Left parameter is const | ||
{ | ||
auto iv = std::views::iota(std::ranges::begin(std::as_const(ev)), std::ranges::end(ev)); | ||
|
||
assert(iv.empty()); | ||
} | ||
// Right parameter is const | ||
{ | ||
auto iv = std::views::iota(std::ranges::begin(ev), std::ranges::end(std::as_const(ev))); | ||
|
||
assert(iv.empty()); | ||
} | ||
// Both parameters are const | ||
{ | ||
auto iv = std::views::iota(std::ranges::begin(std::as_const(ev)), std::ranges::end(std::as_const(ev))); | ||
|
||
assert(iv.empty()); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really understand the purpose of these tests. We're interested in checking that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed |
||
} | ||
|
||
constexpr void test_nonempty_iota() { | ||
// Default ctr | ||
{ | ||
std::ranges::iota_view<Int42<DefaultTo42>> iv; | ||
|
||
assert(!iv.empty()); | ||
} | ||
// Value pass | ||
{ | ||
std::ranges::iota_view<SomeInt> iv(SomeInt(94)); | ||
|
||
assert(!iv.empty()); | ||
} | ||
|
||
{ | ||
std::vector<char> v; | ||
auto it = std::back_inserter(v); | ||
auto iv = std::views::iota(it); | ||
|
||
assert(!iv.empty()); | ||
} | ||
{ | ||
std::vector<char> v{'b', 'a', 'b', 'a', 'z', 'm', 't'}; | ||
auto it = std::back_inserter(v); | ||
auto iv = std::views::iota(it); | ||
|
||
assert(!iv.empty()); | ||
} | ||
} | ||
|
||
constexpr bool test() { | ||
test_empty_iota(); | ||
test_nonempty_iota(); | ||
|
||
return true; | ||
} | ||
|
||
int main(int, char**) { | ||
test(); | ||
static_assert(test()); | ||
|
||
return 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise you don't test anywhere that the method is marked as
const
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done