| 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 | |
| 12 | struct 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 |
| 24 | struct 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 |
| 36 | template <bool conv_c, bool conv_nc, bool ctor_nt_c, bool ctor_nt_nc> |
| 37 | struct IntConfig { |
| 38 | int val; |
| 39 | constexpr explicit IntConfig(int val_) : val(val_) {} |
| 40 | constexpr operator int() noexcept(ctor_nt_nc) |
| 41 | requires(conv_nc) |
| 42 | { |
| 43 | return val; |
| 44 | } |
| 45 | constexpr operator int() const noexcept(ctor_nt_c) |
| 46 | requires(conv_c) |
| 47 | { |
| 48 | return val; |
| 49 | } |
| 50 | }; |
| 51 | |
| 52 | #endif // TEST_STD_CONTAINERS_VIEWS_MDSPAN_CONVERTIBLE_TO_INTEGRAL_H |
| 53 | |