Skip to content

Commit c79eab6

Browse files
use SFINAE
1 parent a3b7579 commit c79eab6

File tree

2 files changed

+63
-26
lines changed

2 files changed

+63
-26
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// REQUIRES: std-at-least-c++26
10+
11+
#include <cassert>
12+
#include <list>
13+
#include <ranges>
14+
#include <vector>
15+
#include "test_iterators.h"
16+
#include "test_macros.h"
17+
18+
// This tests https://cplusplus.github.io/LWG/issue4082
19+
// views::concat(r) is well-formed when r is an output_range
20+
21+
template<typename T>
22+
concept WellFormedView = requires(T& a) {
23+
std::views::concat(a);
24+
};
25+
26+
struct InputRange {
27+
using Iterator = cpp17_input_iterator<int*>;
28+
using Sentinel = sentinel_wrapper<Iterator>;
29+
constexpr InputRange(int* b, int *e): begin_(b), end_(e) {}
30+
constexpr Iterator begin() { return Iterator(begin_); }
31+
constexpr Sentinel end() { return Sentinel(Iterator(end_)); }
32+
33+
private:
34+
int* begin_;
35+
int* end_;
36+
};
37+
38+
39+
int main(int, char**) {
40+
41+
// rejects when it is an output range
42+
{
43+
std::vector<int> v{1,2,3};
44+
static_assert(!WellFormedView<decltype(std::views::counted(std::back_inserter(v), 3))>);
45+
}
46+
47+
// input range
48+
{
49+
static_assert(WellFormedView<InputRange>);
50+
}
51+
52+
// bidirectional range
53+
{
54+
static_assert(WellFormedView<std::list<int>>);
55+
}
56+
57+
// random access range
58+
{
59+
static_assert(WellFormedView<std::vector<int>>);
60+
}
61+
62+
return 0;
63+
}

libcxx/test/std/ranges/range.adaptors/range.concat/constraints.verify.cpp

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)