vir-simd 0.4.189
Parallelism TS 2 extensions and simd fallback implementation
Loading...
Searching...
No Matches
simd_cvt.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_CVT_H_
7#define VIR_SIMD_CVT_H_
8
9#include "simd_concepts.h"
10#if VIR_HAVE_SIMD_CONCEPTS
11#define VIR_HAVE_SIMD_CVT 1
12
13namespace vir
14{
15 template <typename T>
16 class cvt
17 {
18 const T& ref;
19
20 public:
21 constexpr
22 cvt(const T& x)
23 : ref(x)
24 {}
25
26 cvt(const cvt&) = delete;
27
28 template <typename U>
29 requires std::convertible_to<T, U> or requires(const T&x)
30 {
31 { stdx::static_simd_cast<U>(x) } -> std::same_as<U>;
32 }
33 constexpr
34 operator U() const
35 {
36 if constexpr (std::convertible_to<T, U>)
37 return ref;
38 else
39 return stdx::static_simd_cast<U>(ref);
40 }
41 };
42}
43
44#endif // VIR_HAVE_SIMD_CONCEPTS
45#endif // VIR_SIMD_CVT_H_
46// 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).