brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · 67eaaca Raw
57 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// take_while_view() requires default_initializable<V> && default_initializable<Pred> = default;12 13#include <cassert>14#include <ranges>15#include <type_traits>16 17template <bool defaultInitable>18struct View : std::ranges::view_base {19  int i;20  constexpr explicit View()21    requires defaultInitable22  = default;23  int* begin() const;24  int* end() const;25};26 27template <bool defaultInitable>28struct Pred {29  int i;30  constexpr explicit Pred()31    requires defaultInitable32  = default;33  bool operator()(int) const;34};35 36// clang-format off37static_assert( std::is_default_constructible_v<std::ranges::take_while_view<View<true >, Pred<true >>>);38static_assert(!std::is_default_constructible_v<std::ranges::take_while_view<View<false>, Pred<true >>>);39static_assert(!std::is_default_constructible_v<std::ranges::take_while_view<View<true >, Pred<false>>>);40static_assert(!std::is_default_constructible_v<std::ranges::take_while_view<View<false>, Pred<false>>>);41// clang-format on42 43constexpr bool test() {44  {45    std::ranges::take_while_view<View<true>, Pred<true>> twv = {};46    assert(twv.base().i == 0);47    assert(twv.pred().i == 0);48  }49  return true;50}51 52int main(int, char**) {53  test();54  static_assert(test());55  return 0;56}57