Skip to content

Commit

Permalink
Removed last range being sized from concat-is-random-access. (incompl…
Browse files Browse the repository at this point in the history
…ete implementation, expected failing test)
  • Loading branch information
slymz committed Jun 9, 2023
1 parent 4f3210d commit e767c3c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 16 deletions.
2 changes: 1 addition & 1 deletion concat.lwg.feedback.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
- [Done] that "expect" needs to be "except"
- Hui: could not find any expect
- Levent: I checked earliest revisions. No "expect" indeed. Not sure what this was.
- Hui: I found that in the mattermost chat, Thomasz suggested wording for concat-bidi which has expect. It should refer to that. I also used his suggested wording now
- Hui: I found that in the mattermost chat, Tomasz suggested wording for concat-bidi which has expect. It should refer to that. I also used his suggested wording now

# Todos

Expand Down
28 changes: 20 additions & 8 deletions concat.md
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,7 @@ namespace std::ranges {
concept @_concatable_@ = @*see below*@; // exposition only

template <bool Const, class... Rs>
concept @_concat-is-random-access_@ = // exposition only
((random_access_range<@*maybe-const*@<Const, Rs>> &&
sized_range<@*maybe-const*@<Const, Rs>>) && ...);
concept @_concat-is-random-access_@ = @*see below*@; // exposition only

template <class R>
concept @_constant-time-reversible_@ = // exposition only
Expand Down Expand Up @@ -639,7 +637,16 @@ concept @_concat-is-bidirectional_@ = @*see below*@; // exposition only

:::bq

[3]{.pnum} Let `V` be the last element of `Rs`, and `Fs` be the pack that consists of all elements of `Rs` except `V`, then `@_concat-is-bidirectional_@` is equivalent to:
[3]{.pnum} Let `Fs` be the pack that consists of all elements of `Rs` except the last, then `@_concat-is-random-access_@` is equivalent to:

```cpp
template <bool Const, class... Rs>
concept @_concat-is-random-access_@ = // exposition only
(@*all-random-access*@<Const, Rs> && ...) &&
(sized_range<@*maybe-const*@<Const, Fs>> && ...)
```
[4]{.pnum} Let `V` be the last element of `Rs`, and `Fs` be the pack that consists of all elements of `Rs` except `V`, then `@_concat-is-bidirectional_@` is equivalent to:
```cpp
template <bool Const, class... Rs>
Expand All @@ -655,7 +662,7 @@ constexpr explicit concat_view(Views... views);
:::bq
[4]{.pnum} *Effects*: Initializes `@*views_*@` with `std::move(views)...`.
[5]{.pnum} *Effects*: Initializes `@*views_*@` with `std::move(views)...`.
:::
Expand All @@ -667,7 +674,7 @@ constexpr @_iterator_@<true> begin() const

:::bq

[5]{.pnum} *Effects*: Let `@*is-const*@` be `true` for the const-qualified overload,
[6]{.pnum} *Effects*: Let `@*is-const*@` be `true` for the const-qualified overload,
and `false` otherwise. Equivalent to:

```cpp
Expand All @@ -685,7 +692,7 @@ constexpr auto end() const requires(range<const Views>&&...);

:::bq

[6]{.pnum} *Effects*: Let `@*is-const*@` be `true` for the const-qualified overload,
[7]{.pnum} *Effects*: Let `@*is-const*@` be `true` for the const-qualified overload,
and `false` otherwise, and let `@_last-view_@` be the last element of the pack
`const Views...` for the const-qualified overload, and the last element of the pack
`Views...` otherwise. Equivalent to:
Expand All @@ -709,7 +716,7 @@ constexpr auto size() const requires(sized_range<const Views>&&...);
:::bq
[7]{.pnum} *Effects*: Equivalent to:
[8]{.pnum} *Effects*: Equivalent to:
```cpp
return apply(
Expand Down Expand Up @@ -1403,6 +1410,11 @@ only if: For every combination of two types `X` and `Y` in the set of all types
in the parameter pack `iterator_t<@_maybe-const_@<Const, Views>>>...`,
`indirectly_swappable<X, Y>` is modelled.

requires(indirectly_swappable<iterator_t<__maybe_const<Const, Views>>> && ... &&
swappable_with<xo::concat_reference_t<__maybe_const<Const, Views>...>,
xo::concat_reference_t<__maybe_const<Const, Views>...>>)


:::

## Feature Test Macro
Expand Down
24 changes: 17 additions & 7 deletions impl/concat/concat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ namespace std::ranges {

namespace xo { // exposition only things (and persevering face)

template <bool Const, class... Views>
concept all_random_access = (random_access_range<__maybe_const<Const, Views>> && ...);
template <bool Const, class... Views>
concept all_bidirectional = (bidirectional_range<__maybe_const<Const, Views>> && ...);
template <bool Const, class... Views>
concept all_forward = (forward_range<__maybe_const<Const, Views>> && ...);

inline namespace not_to_spec {

template <class... Rs>
Expand Down Expand Up @@ -63,24 +70,27 @@ template <class... T>
using back = tuple_element_t<sizeof...(T) - 1, tuple<T...>>;

template <bool... b, size_t... I>
consteval bool all_but_last(std::index_sequence<I...>) {
consteval bool all_but_last_impl(std::index_sequence<I...>) {
return ((I == sizeof...(I) - 1 || b) && ...);
}


template <bool... b>
constexpr bool all_but_last = all_but_last_impl<b...>(make_index_sequence<sizeof...(b)>{});

} // namespace not_to_spec

template <bool Const, class... Views>
concept concat_is_random_access = ((random_access_range<__maybe_const<Const, Views>> &&
sized_range<__maybe_const<Const, Views>>)&&...);
concept concat_is_random_access = (all_random_access<Const, Views> && ...) &&
(all_but_last<sized_range<__maybe_const<Const, Views>>...>);

template <class R>
concept constant_time_reversible =
(bidirectional_range<R> && common_range<R>) || (sized_range<R> && random_access_range<R>);
concept constant_time_reversible = (bidirectional_range<R> && common_range<R>) ||
(sized_range<R> && random_access_range<R>);

template <class... Rs>
concept concat_bidirectional =
all_but_last<constant_time_reversible<Rs>...>(index_sequence_for<Rs...>{}) &&
bidirectional_range<back<Rs...>>;
all_but_last<constant_time_reversible<Rs>...> && bidirectional_range<back<Rs...>>;


static_assert(true); // clang-format badness
Expand Down
13 changes: 13 additions & 0 deletions impl/concat/test/basics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,19 @@ TEST_POINT("end_last_range_non_common_but_random_sized") {
REQUIRE(it2 == st2);
}

TEST_POINT("end_last_range_non_common_but_random_and_not_sized") {
std::vector<int> v1{1};
auto io = std::views::iota(0);
static_assert(!std::ranges::sized_range<decltype(io)>);
std::ranges::concat_view cv1{v1, io};
std::ranges::concat_view cv2{io, v1};
static_assert(std::ranges::random_access_range<decltype(cv1)>);
static_assert(!std::ranges::random_access_range<decltype(cv2)>);
static_assert(std::ranges::sized_range<decltype(cv1)>);
static_assert(!std::ranges::sized_range<decltype(cv2)>);
}


TEST_POINT("operator++") {
using V = std::vector<int>;
V v1{}, v2{4, 5}, v3{}, v4{6};
Expand Down

0 comments on commit e767c3c

Please sign in to comment.