• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 // constexpr T const& operator*() const;
12 // constexpr T& operator*();
13 
14 #include <ranges>
15 
16 #include <cassert>
17 
18 template <class T>
test()19 constexpr void test() {
20   using Cache = std::ranges::__non_propagating_cache<T>;
21 
22   // non-const version
23   {
24     Cache cache; cache.__emplace(3);
25     T& result = *cache;
26     assert(result == T{3});
27   }
28 
29   // const version
30   {
31     Cache cache; cache.__emplace(3);
32     T const& result = *static_cast<Cache const&>(cache);
33     assert(result == T{3});
34   }
35 }
36 
37 struct T {
38   int x;
TT39   constexpr explicit T(int i) : x(i) { }
operator ==T40   constexpr bool operator==(T const& other) const { return x == other.x; }
41 };
42 
tests()43 constexpr bool tests() {
44   test<T>();
45   test<int>();
46   return true;
47 }
48 
main(int,char **)49 int main(int, char**) {
50   static_assert(tests());
51   tests();
52   return 0;
53 }
54