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// UNSUPPORTED: c++03, c++11, c++14
10
11// <experimental/simd>
12//
13// [simd.class]
14// template<class U> simd_mask(const simd_mask<U, simd_abi::fixed_size<size()>>&) noexcept;
15
16#include "../test_utils.h"
17#include <experimental/simd>
18
19namespace ex = std::experimental::parallelism_v2;
20
21template <class T, class SimdAbi, std::size_t array_size>
22struct ConversionHelper {
23 const std::array<bool, array_size>& expected_value;
24
25 ConversionHelper(const std::array<bool, array_size>& value) : expected_value(value) {}
26
27 template <class U>
28 void operator()() const {
29 if constexpr (!std::is_same_v<U, T> && std::is_same_v<SimdAbi, ex::simd_abi::fixed_size<array_size>>) {
30 static_assert(noexcept(ex::simd_mask<T, SimdAbi>(ex::simd_mask<U, SimdAbi>{})));
31 ex::simd_mask<U, SimdAbi> origin_mask(false);
32 ex::simd_mask<T, SimdAbi> mask_from_implicit_conversion(origin_mask);
33 assert_simd_mask_values_equal<array_size>(mask_from_implicit_conversion, expected_value);
34 }
35 }
36};
37
38template <class T, std::size_t>
39struct CheckConversionMaskCtor {
40 template <class SimdAbi>
41 void operator()() {
42 constexpr std::size_t array_size = ex::simd_size_v<T, SimdAbi>;
43 std::array<bool, array_size> expected_value{};
44
45 types::for_each(simd_test_types(), ConversionHelper<T, SimdAbi, array_size>(expected_value));
46 }
47};
48
49template <class T, class SimdAbi, std::size_t array_size>
50struct CheckConversionMaskCtorTraitsHelper {
51 template <class U>
52 void operator()() {
53 if constexpr (!std::is_same_v<U, T>) {
54 if constexpr (std::is_same_v<SimdAbi, ex::simd_abi::fixed_size<array_size>>)
55 static_assert(std::is_convertible_v<ex::simd_mask<U, SimdAbi>, ex::simd_mask<T, SimdAbi>>);
56 else
57 static_assert(!std::is_convertible_v<ex::simd_mask<U, SimdAbi>, ex::simd_mask<T, SimdAbi>>);
58 }
59 }
60};
61
62template <class T, std::size_t>
63struct CheckConversionMaskCtorTraits {
64 template <class SimdAbi>
65 void operator()() {
66 constexpr std::size_t array_size = ex::simd_size_v<T, SimdAbi>;
67
68 types::for_each(simd_test_types(), CheckConversionMaskCtorTraitsHelper<T, SimdAbi, array_size>());
69 }
70};
71
72int main(int, char**) {
73 test_all_simd_abi<CheckConversionMaskCtor>();
74 test_all_simd_abi<CheckConversionMaskCtorTraits>();
75 return 0;
76}
77

source code of libcxx/test/std/experimental/simd/simd.mask.class/simd_mask_ctor_conversion.pass.cpp