brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · b342d1a Raw
50 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++17, c++2010 11// <mdspan>12 13// constexpr data_handle_type offset(data_handle_type p, size_t i) const noexcept;14//15// Effects: Equivalent to: return p+i;16 17#include <mdspan>18#include <cassert>19#include <type_traits>20 21#include "test_macros.h"22 23#include "../MinimalElementType.h"24 25template <class T>26constexpr void test_offset() {27  ElementPool<std::remove_const_t<T>, 10> data;28  T* ptr = data.get_ptr();29  std::default_accessor<T> acc;30  for (int i = 0; i < 10; i++) {31    static_assert(std::is_same_v<decltype(acc.offset(ptr, i)), typename std::default_accessor<T>::data_handle_type>);32    ASSERT_NOEXCEPT(acc.offset(ptr, i));33    assert(acc.offset(ptr, i) == ptr + i);34  }35}36 37constexpr bool test() {38  test_offset<int>();39  test_offset<const int>();40  test_offset<MinimalElementType>();41  test_offset<const MinimalElementType>();42  return true;43}44 45int main(int, char**) {46  test();47  static_assert(test());48  return 0;49}50