[MemProf] Templatize CallStackRadixTreeBuilder (NFC) (#117014)
[llvm-project.git] / libcxx / test / std / containers / views / mdspan / default_accessor / offset.pass.cpp
blob5842ff91796347588c961ad11e5e2cad6b8455a2
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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
11 // <mdspan>
13 // constexpr data_handle_type offset(data_handle_type p, size_t i) const noexcept;
15 // Effects: Equivalent to: return p+i;
17 #include <mdspan>
18 #include <cassert>
19 #include <type_traits>
21 #include "test_macros.h"
23 #include "../MinimalElementType.h"
25 template <class T>
26 constexpr 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);
37 constexpr bool test() {
38 test_offset<int>();
39 test_offset<const int>();
40 test_offset<MinimalElementType>();
41 test_offset<const MinimalElementType>();
42 return true;
45 int main(int, char**) {
46 test();
47 static_assert(test());
48 return 0;