]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/std/ranges/adaptors/sizeof.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / std / ranges / adaptors / sizeof.cc
1 // Copyright (C) 2020-2021 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
17
18 // { dg-options "-std=gnu++2a" }
19 // { dg-do compile { target c++2a } }
20
21 #include <ranges>
22 #include <string_view>
23
24 namespace ranges = std::ranges;
25
26 auto pred_f(int x) { return x%2 == 0; };
27 auto pred_l = [] (int x) { return x%2 == 0; };
28
29 auto func_f(int x) { return x*x; }
30 auto func_l = [] (int x) { return x*x; };
31
32 using V = ranges::subrange<int*, int*>;
33 constexpr auto ptr = sizeof(int*);
34 static_assert(sizeof(V) == 2*ptr);
35
36 static_assert(sizeof(ranges::take_view<V>) == 3*ptr);
37 static_assert(sizeof(ranges::drop_view<V>) == 3*ptr);
38
39 static_assert(sizeof(ranges::filter_view<V, decltype(&pred_f)>) == 4*ptr);
40 static_assert(sizeof(ranges::take_while_view<V, decltype(&pred_f)>) == 3*ptr);
41 static_assert(sizeof(ranges::drop_while_view<V, decltype(&pred_f)>) == 4*ptr);
42 static_assert(sizeof(ranges::transform_view<V, decltype(&func_f)>) == 3*ptr);
43
44 static_assert(sizeof(ranges::filter_view<V, decltype(pred_l)>) == 3*ptr);
45 static_assert(sizeof(ranges::take_while_view<V, decltype(pred_l)>) == 3*ptr);
46 static_assert(sizeof(ranges::drop_while_view<V, decltype(pred_l)>) == 3*ptr);
47 static_assert(sizeof(ranges::transform_view<V, decltype(func_l)>) == 3*ptr);
48
49 static_assert(sizeof(ranges::split_view<V, std::string_view>) == 4*ptr);
50
51 static_assert
52 (sizeof(ranges::reverse_view<ranges::filter_view<V, decltype(pred_l)>>) == 4*ptr);