brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 5cd20bc Raw
63 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++1710 11// <ranges>12//13// Range adaptors that take predicates should support predicates that return a non-boolean14// value as long as the returned type is implicitly convertible to bool.15 16#include <ranges>17 18#include "boolean_testable.h"19 20template <std::ranges::view View>21constexpr void use(View view) {22  // Just use the view in a few ways. Our goal here is to trigger the instantiation23  // of various functions related to the view and its iterators in the hopes that we24  // instantiate functions that might have incorrect implementations w.r.t. predicates.25  auto first = std::ranges::begin(view);26  auto last  = std::ranges::end(view);27  ++first;28  --first;29  (void)(first == last);30  (void)(first != last);31  (void)std::ranges::empty(view);32}33 34using Value    = StrictComparable<int>;35using Iterator = StrictBooleanIterator<Value*>;36using Range    = std::ranges::subrange<Iterator>;37auto pred1     = StrictUnaryPredicate;38auto pred2     = StrictBinaryPredicate;39 40void f(Range in) {41  (void)pred1;42  (void)pred2;43 44#if TEST_STD_VER >= 2345  {46    auto view = std::views::chunk_by(in, pred2);47    use(view);48  }49#endif50  {51    auto view = std::views::drop_while(in, pred1);52    use(view);53  }54  {55    auto view = std::views::filter(in, pred1);56    use(view);57  }58  {59    auto view = std::views::take_while(in, pred1);60    use(view);61  }62}63