brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · c09fd52 Raw
59 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// constexpr explicit single_view(const T& t);12// constexpr explicit single_view(T&& t);13 14#include <cassert>15#include <ranges>16#include <utility>17 18#include "test_macros.h"19 20struct Empty {};21struct BigType { char buffer[64] = {10}; };22 23constexpr bool test() {24  {25    BigType bt;26    std::ranges::single_view<BigType> sv(bt);27    assert(sv.data()->buffer[0] == 10);28    assert(sv.size() == 1);29  }30  {31    const BigType bt;32    const std::ranges::single_view<BigType> sv(bt);33    assert(sv.data()->buffer[0] == 10);34    assert(sv.size() == 1);35  }36 37  {38    BigType bt;39    std::ranges::single_view<BigType> sv(std::move(bt));40    assert(sv.data()->buffer[0] == 10);41    assert(sv.size() == 1);42  }43  {44    const BigType bt;45    const std::ranges::single_view<BigType> sv(std::move(bt));46    assert(sv.data()->buffer[0] == 10);47    assert(sv.size() == 1);48  }49 50  return true;51}52 53int main(int, char**) {54  test();55  static_assert(test());56 57  return 0;58}59