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
}
概要
符号なし整数要素をもつ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]);
}
}
出力
0000000000000000 -> 0
0000000000000001 -> 1
0000000000000100 -> 3
0000000000000111 -> 3
バージョン
言語
- C++26
処理系
- Clang: 22 ❌
- GCC: 16.1 ❌
- Visual C++: 2026 Update 2 ❌
関連項目
参照
- 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で