[MemProf] Templatize CallStackRadixTreeBuilder (NFC) (#117014)
[llvm-project.git] / libcxx / test / std / containers / views / mdspan / default_accessor / ctor.conversion.pass.cpp
blob299d98f0b2d01d90e92e2af0de723432ca458ef7
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 // Test converting constructor:
15 // template<class OtherElementType>
16 // constexpr default_accessor(default_accessor<OtherElementType>) noexcept {}
18 // Constraints: is_convertible_v<OtherElementType(*)[], element_type(*)[]> is true.
20 #include <mdspan>
21 #include <cassert>
22 #include <cstdint>
23 #include <type_traits>
25 #include "test_macros.h"
27 #include "../MinimalElementType.h"
29 struct Base {};
30 struct Derived: public Base {};
32 template <class FromT, class ToT>
33 constexpr void test_conversion() {
34 std::default_accessor<FromT> acc_from;
35 ASSERT_NOEXCEPT(std::default_accessor<ToT>(acc_from));
36 [[maybe_unused]] std::default_accessor<ToT> acc_to(acc_from);
39 constexpr bool test() {
40 // default accessor conversion largely behaves like pointer conversion
41 test_conversion<int, int>();
42 test_conversion<int, const int>();
43 test_conversion<const int, const int>();
44 test_conversion<MinimalElementType, MinimalElementType>();
45 test_conversion<MinimalElementType, const MinimalElementType>();
46 test_conversion<const MinimalElementType, const MinimalElementType>();
48 // char is convertible to int, but accessors are not
49 static_assert(!std::is_constructible_v<std::default_accessor<int>, std::default_accessor<char>>);
50 // don't allow conversion from const elements to non-const
51 static_assert(!std::is_constructible_v<std::default_accessor<int>, std::default_accessor<const int>>);
52 // MinimalElementType is constructible from int, but accessors should not be convertible
53 static_assert(!std::is_constructible_v<std::default_accessor<MinimalElementType>, std::default_accessor<int>>);
54 // don't allow conversion from const elements to non-const
55 static_assert(!std::is_constructible_v<std::default_accessor<MinimalElementType>, std::default_accessor<const MinimalElementType>>);
56 // don't allow conversion from Base to Derived
57 static_assert(!std::is_constructible_v<std::default_accessor<Derived>, std::default_accessor<Base>>);
58 // don't allow conversion from Derived to Base
59 static_assert(!std::is_constructible_v<std::default_accessor<Base>, std::default_accessor<Derived>>);
61 return true;
64 int main(int, char**) {
65 test();
66 static_assert(test());
67 return 0;