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 transform_view(View, F);
13 
14 #include <ranges>
15 
16 #include <cassert>
17 
18 struct Range : std::ranges::view_base {
RangeRange19   constexpr explicit Range(int* b, int* e) : begin_(b), end_(e) { }
beginRange20   constexpr int* begin() const { return begin_; }
endRange21   constexpr int* end() const { return end_; }
22 
23 private:
24   int* begin_;
25   int* end_;
26 };
27 
28 struct F {
operator ()F29   constexpr int operator()(int i) const { return i + 100; }
30 };
31 
test()32 constexpr bool test() {
33   int buff[] = {1, 2, 3, 4, 5, 6, 7, 8};
34 
35   {
36     Range range(buff, buff + 8);
37     F f;
38     std::ranges::transform_view<Range, F> view(range, f);
39     assert(view[0] == 101);
40     assert(view[1] == 102);
41     // ...
42     assert(view[7] == 108);
43   }
44 
45   {
46     Range range(buff, buff + 8);
47     F f;
48     std::ranges::transform_view<Range, F> view = {range, f};
49     assert(view[0] == 101);
50     assert(view[1] == 102);
51     // ...
52     assert(view[7] == 108);
53   }
54 
55   return true;
56 }
57 
main(int,char **)58 int main(int, char**) {
59   test();
60   static_assert(test());
61 
62   return 0;
63 }
64