1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
10 // XFAIL: target=powerpc{{.*}}le-unknown-linux-gnu
12 // <experimental/simd>
15 // template<class G> explicit simd(G&& gen) noexcept;
17 #include "../test_utils.h"
18 #include <experimental/simd>
20 namespace ex
= std::experimental::parallelism_v2
;
22 template <class T
, std::size_t>
23 struct CheckGenerateSimdCtor
{
24 template <class SimdAbi
>
26 ex::simd
<T
, SimdAbi
> origin_simd([](T i
) { return i
; });
27 constexpr size_t array_size
= origin_simd
.size();
28 std::array
<T
, array_size
> expected_value
;
29 for (size_t i
= 0; i
< array_size
; ++i
)
30 expected_value
[i
] = static_cast<T
>(i
);
31 assert_simd_values_equal
<array_size
>(origin_simd
, expected_value
);
35 template <class U
, class T
, class SimdAbi
= ex::simd_abi::compatible
<T
>, class = void>
36 struct has_generate_ctor
: std::false_type
{};
38 template <class U
, class T
, class SimdAbi
>
39 struct has_generate_ctor
<U
, T
, SimdAbi
, std::void_t
<decltype(ex::simd
<T
, SimdAbi
>(std::declval
<U
>()))>>
42 template <class T
, std::size_t>
43 struct CheckGenerateCtorTraits
{
44 template <class SimdAbi
>
46 static_assert(!has_generate_ctor
<SimdAbi
, T
, SimdAbi
>::value
);
48 auto func
= [](T i
) { return i
; };
49 static_assert(has_generate_ctor
<decltype(func
), T
, SimdAbi
>::value
);
53 int main(int, char**) {
54 test_all_simd_abi
<CheckGenerateSimdCtor
>();
55 test_all_simd_abi
<CheckGenerateCtorTraits
>();