- simd[meta header]
- std::simd[meta namespace]
- function template[meta id-type]
- cpp26[meta cpp]
namespace std::simd {
template<simd-vec-type V>
constexpr rebind_t<make_signed_t<typename V::value_type>, V>
bit_width(const V& v) noexcept; // C++26
}- simd-vec-type[link /reference/simd/simd-vec-type.md]
- make_signed_t[link /reference/type_traits/make_signed.md]
符号なし整数要素をもつbasic_vecの各要素に対して、std::bit_widthを要素ごとに適用し、各要素を表現するのに必要なビット数を求める。
V::value_typeが符号なし整数型であること
i番目の要素がstd::bit_width(v[i])で初期化されたbasic_vecオブジェクトを返す。要素型はV::value_typeを符号付き整数型にしたものである。
投げない
#include <simd>
#include <print>
#include <array>
#include <cstdint>
namespace simd = std::simd;
int main()
{
std::array data = {0b000u, 0b001u, 0b100u, 0b111u};
simd::vec<std::uint32_t, 4> v {[&](int i) { return data[i]; }};
auto r = simd::bit_width(v);
for (int i = 0; i < v.size(); ++i) {
std::println("{:016b} -> {}", v[i], r[i]);
}
}- simd::bit_width[color ff0000]
0000000000000000 -> 0
0000000000000001 -> 1
0000000000000100 -> 3
0000000000000111 -> 3
- C++26
- Clang: 22 [mark noimpl]
- GCC: 16.1 [mark noimpl]
- Visual C++: 2026 Update 2 [mark noimpl]
- P1928R15 std::simd — merge data-parallel types from the Parallelism TS 2
- C++26で
std::simdライブラリが追加された
- C++26で
- P2933R4 Extend
<bit>header function with overloads forstd::simd- C++26で
<bit>ヘッダの関数にstd::simd向けのオーバーロードが追加された
- C++26で