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 // <ranges>
14 
15 // template<class T>
16 // inline constexpr bool enable_view = ...;
17 
18 #include <ranges>
19 
20 #include "test_macros.h"
21 
22 // Doesn't derive from view_base
23 struct Empty { };
24 static_assert(!std::ranges::enable_view<Empty>);
25 
26 // Derives from view_base, but privately
27 struct PrivateViewBase : private std::ranges::view_base { };
28 static_assert(!std::ranges::enable_view<PrivateViewBase>);
29 
30 // Derives from view_base, but specializes enable_view to false
31 struct EnableViewFalse : std::ranges::view_base { };
32 namespace std::ranges { template <> constexpr bool enable_view<EnableViewFalse> = false; }
33 static_assert(!std::ranges::enable_view<EnableViewFalse>);
34 
35 
36 // Derives from view_base
37 struct PublicViewBase : std::ranges::view_base { };
38 static_assert(std::ranges::enable_view<PublicViewBase>);
39 
40 // Does not derive from view_base, but specializes enable_view to true
41 struct EnableViewTrue { };
42 namespace std::ranges { template <> constexpr bool enable_view<EnableViewTrue> = true; }
43 static_assert(std::ranges::enable_view<EnableViewTrue>);
44 
45 
46 // Make sure that enable_view is a bool, not some other contextually-convertible-to-bool type.
47 ASSERT_SAME_TYPE(decltype(std::ranges::enable_view<Empty>), const bool);
48 ASSERT_SAME_TYPE(decltype(std::ranges::enable_view<PublicViewBase>), const bool);
49