vir-simd 0.4.189
Parallelism TS 2 extensions and simd fallback implementation
Loading...
Searching...
No Matches
simd_iota.h
1/* SPDX-License-Identifier: LGPL-3.0-or-later */
2/* Copyright © 2023–2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
3 * Matthias Kretz <m.kretz@gsi.de>
4 */
5
6#ifndef VIR_SIMD_IOTA_H_
7#define VIR_SIMD_IOTA_H_
8
9#include "simd.h"
10#include "detail.h"
11#include "simd_concepts.h"
12#if VIR_HAVE_SIMD_CONCEPTS
13#define VIR_HAVE_SIMD_IOTA 1
14#include <array>
15
16namespace vir
17{
18 namespace detail
19 {
20 template <typename T, typename>
21 struct iota_array;
22
23 template <typename T, std::size_t... Is>
24 struct iota_array<T, std::index_sequence<Is...>>
25 { static constexpr T data[sizeof...(Is)] = {static_cast<T>(Is)...}; };
26 }
27
28 template <typename T>
29 inline constexpr T
30 iota_v;
31
32 template <typename T>
33 requires(std::is_arithmetic_v<T>)
34 inline constexpr T
35 iota_v<T> = T();
36
37 template <vir::any_simd T>
38 inline VIR_SIMD_CONSTEXPR_SIMD T
39 iota_v<T> = T([](int i) { return static_cast<typename T::value_type>(i); });
40
41 template <typename T, std::size_t N>
42 inline constexpr std::array<T, N>
43 iota_v<std::array<T, N>> = []<std::size_t... Is>(std::index_sequence<Is...>) {
44 return std::array<T, N>{static_cast<T>(Is)...};
45 }(std::make_index_sequence<N>());
46
47 template <typename T, std::size_t N>
48 inline constexpr auto&
49 iota_v<T[N]> = detail::iota_array<T, decltype(std::make_index_sequence<N>())>::data;
50}
51
52#endif // VIR_HAVE_SIMD_CONCEPTS
53#endif // VIR_SIMD_IOTA_H_
54
55// vim: noet cc=101 tw=100 sw=2 ts=8
This namespace collects libraries and tools authored by Matthias Kretz.
Definition constexpr_wrapper.h:21
C++20 concepts extending the Parallelism TS 2 (which is limited to C++17).