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