Skip to content

Commit

Permalink
Deploying to gh-pages from @ afcad24 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
slymz committed Jun 9, 2023
1 parent 240c2b0 commit a3bbb25
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
4 changes: 2 additions & 2 deletions concat.md
Original file line number Diff line number Diff line change
Expand Up @@ -642,8 +642,8 @@ concept @_concat-is-bidirectional_@ = @*see below*@; // exposition only
```cpp
template <bool Const, class... Rs>
concept @_concat-is-random-access_@ = // exposition only
(... && @*all-random-access*@<Const, Rs>) &&
(... && sized_range<@*maybe-const*@<Const, Fs>>)
(@*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:
Expand Down
4 changes: 2 additions & 2 deletions generated/concat.html
Original file line number Diff line number Diff line change
Expand Up @@ -1236,8 +1236,8 @@ <h4 class="unnumbered" id="class-template-concat_view-range.concat.view">?.?.?.2
is equivalent to:</p>
<div class="sourceCode" id="cb21"><pre class="sourceCode cpp"><code class="sourceCode cpp"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a><span class="kw">template</span> <span class="op">&lt;</span><span class="dt">bool</span> Const, <span class="kw">class</span><span class="op">...</span> Rs<span class="op">&gt;</span></span>
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a><span class="kw">concept</span> <em>concat-is-random-access</em> <span class="op">=</span> <span class="co">// exposition only</span></span>
<span id="cb21-3"><a href="#cb21-3" aria-hidden="true" tabindex="-1"></a> <span class="op">(...</span> <span class="op">&amp;&amp;</span> <em>all-random-access</em><span class="op">&lt;</span>Const, Rs<span class="op">&gt;)</span> <span class="op">&amp;&amp;</span></span>
<span id="cb21-4"><a href="#cb21-4" aria-hidden="true" tabindex="-1"></a> <span class="op">(...</span> <span class="op">&amp;&amp;</span> sized_range<span class="op">&lt;</span><em>maybe-const</em><span class="op">&lt;</span>Const, Fs<span class="op">&gt;&gt;)</span></span></code></pre></div>
<span id="cb21-3"><a href="#cb21-3" aria-hidden="true" tabindex="-1"></a> <span class="op">(</span><em>all-random-access</em><span class="op">&lt;</span>Const, Rs<span class="op">&gt;</span> <span class="op">&amp;&amp;</span> <span class="op">...)</span> <span class="op">&amp;&amp;</span></span>
<span id="cb21-4"><a href="#cb21-4" aria-hidden="true" tabindex="-1"></a> <span class="op">(</span>sized_range<span class="op">&lt;</span><em>maybe-const</em><span class="op">&lt;</span>Const, Fs<span class="op">&gt;&gt;</span> <span class="op">&amp;&amp;</span> <span class="op">...)</span></span></code></pre></div>
<p><span class="marginalizedparent"><a class="marginalized">4</a></span>
Let <code class="sourceCode default">V</code> be the last element of
<code class="sourceCode default">Rs</code>, and
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 a3bbb25

Please sign in to comment.