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//===----------------------------------------------------------------------===//
8
9#ifndef TEST_STD_CONTAINERS_VIEWS_MDSPAN_CONVERTIBLE_TO_INTEGRAL_H
10#define TEST_STD_CONTAINERS_VIEWS_MDSPAN_CONVERTIBLE_TO_INTEGRAL_H
11
12struct IntType {
13 int val;
14 constexpr IntType() = default;
15 constexpr IntType(int v) noexcept : val(v) {}
16
17 constexpr bool operator==(const IntType& rhs) const { return val == rhs.val; }
18 constexpr operator int() const noexcept { return val; }
19 constexpr operator unsigned char() const { return static_cast<unsigned char>(val); }
20 constexpr operator signed char() const noexcept { return static_cast<signed char>(val); }
21};
22
23// only non-const convertible
24struct IntTypeNC {
25 int val;
26 constexpr IntTypeNC() = default;
27 constexpr IntTypeNC(int v) noexcept : val(v) {}
28
29 constexpr bool operator==(const IntType& rhs) const { return val == rhs.val; }
30 constexpr operator int() noexcept { return val; }
31 constexpr operator unsigned() { return static_cast<unsigned>(val); }
32 constexpr operator char() noexcept { return static_cast<char>(val); }
33};
34
35// weird configurability of convertibility to int
36template<bool conv_c, bool conv_nc, bool ctor_nt_c, bool ctor_nt_nc>
37struct IntConfig {
38 int val;
39 constexpr explicit IntConfig(int val_):val(val_){}
40 constexpr operator int() noexcept(ctor_nt_nc) requires(conv_nc) { return val; }
41 constexpr operator int() const noexcept(ctor_nt_c) requires(conv_c) { return val; }
42};
43
44#endif // TEST_STD_CONTAINERS_VIEWS_MDSPAN_CONVERTIBLE_TO_INTEGRAL_H
45

source code of libcxx/test/std/containers/views/mdspan/ConvertibleToIntegral.h