Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions stl/inc/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,10 @@ namespace ranges {
}
}

_NODISCARD constexpr bool empty() const noexcept(noexcept(_Value == _Bound)) /* strengthened */ {
return _Value == _Bound;
}

#pragma warning(push)
#pragma warning(disable : 4146) // unary minus operator applied to unsigned type, result still unsigned
// clang-format off
Expand Down
39 changes: 39 additions & 0 deletions tests/std/tests/P0896R4_views_iota/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
#include <cassert>
#include <cstddef>
#include <functional>
#include <iterator>
#include <limits>
#include <ranges>
#include <type_traits>
#include <utility>
#include <vector>

using namespace std;

Expand All @@ -20,6 +22,14 @@ concept CanViewIota = requires(W w, B b) { views::iota(w, b); };
template <class R>
concept CanSize = requires(R& r) { ranges::size(r); };

template <class R>
concept CanEmpty = requires(const R& r) { ranges::empty(r); };

template <class R>
concept CanMemberEmpty = requires(const R& r) {
{ r.empty() } -> same_as<bool>;
};

struct empty_type {};

template <class T>
Expand Down Expand Up @@ -374,6 +384,16 @@ int main() {
views::iota(begin(as_const(objects)), end(objects)), objects, ranges::equal_to{}, identity{}, address));
assert(ranges::equal(
views::iota(begin(objects), end(as_const(objects))), objects, ranges::equal_to{}, identity{}, address));

using FirstConstIota = decltype(views::iota(begin(as_const(objects)), end(objects)));
static_assert(CanEmpty<FirstConstIota>);
static_assert(CanMemberEmpty<FirstConstIota>);
static_assert(noexcept(declval<const FirstConstIota&>().empty())); // strengthened

using SecondConstIota = decltype(views::iota(begin(objects), end(as_const(objects))));
static_assert(CanEmpty<SecondConstIota>);
static_assert(CanMemberEmpty<SecondConstIota>);
static_assert(noexcept(declval<const SecondConstIota&>().empty())); // strengthened
}
{
// Iterator and sentinel of a non-common range
Expand All @@ -387,6 +407,25 @@ int main() {
auto r = views::iota(ranges::begin(f), ranges::end(f));

assert(ranges::equal(r, even_ints, ranges::equal_to{}, deref));

using FilteredIota = decltype(r);
static_assert(CanEmpty<FilteredIota>);
static_assert(CanMemberEmpty<FilteredIota>);
}
// LWG-4001 iota_view should provide empty
{
using BackInsertingIota = decltype(views::iota(back_inserter(declval<vector<int>&>())));
static_assert(CanEmpty<BackInsertingIota>);
static_assert(CanMemberEmpty<BackInsertingIota>);
static_assert(noexcept(declval<const BackInsertingIota&>().empty())); // strengthened

constexpr auto test_back_inserting_iota_nonempty = [] {
vector<int> v;
auto vw = views::iota(back_inserter(v));
return !vw.empty();
};
assert(test_back_inserting_iota_nonempty());
static_assert(test_back_inserting_iota_nonempty());
}

test_difference();
Expand Down