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