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 // UNSUPPORTED: c++03, c++11, c++14, c++17
10 // UNSUPPORTED: libcpp-has-no-incomplete-ranges
11
12 // constexpr take_view(V base, range_difference_t<V> count);
13
14 #include <ranges>
15 #include <cassert>
16
17 #include "test_macros.h"
18 #include "test_iterators.h"
19 #include "test_range.h"
20 #include "types.h"
21
test()22 constexpr bool test() {
23 int buffer[8] = {1, 2, 3, 4, 5, 6, 7, 8};
24
25 {
26 std::ranges::take_view<CopyableView> tv(CopyableView{buffer}, 0);
27 assert(tv.base().ptr_ == buffer);
28 assert(tv.begin() == tv.end()); // Checking we have correct size.
29 }
30
31 {
32 std::ranges::take_view<MoveOnlyView> tv(MoveOnlyView{buffer}, 1);
33 assert(std::move(tv).base().ptr_ == buffer);
34 assert(std::ranges::next(tv.begin(), 1) == tv.end()); // Checking we have correct size.
35 }
36
37 {
38 const std::ranges::take_view<CopyableView> tv(CopyableView{buffer}, 2);
39 assert(tv.base().ptr_ == buffer);
40 assert(std::ranges::next(tv.begin(), 2) == tv.end()); // Checking we have correct size.
41 }
42
43 return true;
44 }
45
main(int,char **)46 int main(int, char**) {
47 test();
48 static_assert(test());
49
50 return 0;
51 }
52