Intel xvec
Experimental C++ simd class library
Loading...
Searching...
No Matches
std_rebind.hpp
1//===----------------------------------------------------------------------===//
2//
3// Copyright (C) 2021 Intel Corporation
4//
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#pragma once
10
11#include <complex>
12#include <utility>
13#include <cstddef>
14
15#include <xvec/detail/config.hpp>
16
17// NOTE: rebind_cast deliberately lives one level above `simd`, because P3971R1
18// places it in namespace std. It is a general element-type rebinding facility
19// spanning sequence containers, std::complex and user-defined uniform-element
20// types, of which simd is only one participant; only that participant is
21// implemented here. The simd-specific `simd::rebind_t` alias from C++26 is a
22// separate entity (see detail/core.hpp); the two agree on simd types.
23namespace _XVEC_NAMESPACE::detail
24{
26template<typename _Up, _XVEC_NAMESPACE::simd::vec_type _Vp>
27constexpr _XVEC_NAMESPACE::simd::rebind_t<_Up, _Vp> rebind_cast(const _Vp& v)
28 { return _XVEC_NAMESPACE::simd::rebind_t<_Up, _Vp>(v); }
29
31template<typename _Up>
32struct RebindCast {
33 template<typename _Tp>
34 constexpr auto operator()(_Tp&& t) const -> decltype(rebind_cast<_Up>(std::forward<_Tp>(t))) {
35 return rebind_cast<_Up>(std::forward<_Tp>(t));
36 }
37};
38
39} // namespace _XVEC_NAMESPACE::detail
40
41namespace _XVEC_NAMESPACE
42{
53
55 template<typename _Up> inline constexpr detail::RebindCast<_Up> rebind_cast{};
56
58}
constexpr detail::RebindCast< _Up > rebind_cast
Rebinding CPO.
Definition std_rebind.hpp:55
Customisation point object for rebind_cast.
Definition std_rebind.hpp:32