GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::bit_repeat - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. bit
  3. bit_repeat

最終更新日時: 2026年10月15日 11時31分14秒 (JST)
Akira Takahashi が更新

履歴 編集

function template
<bit>

std::bit_repeat(C++29)

namespace std {
  template <class T>
  constexpr T bit_repeat(T x, int l); // C++29
}

概要

値xの最下位lビットのパターンを、Tの幅いっぱいに繰り返した値を求める。

テンプレートパラメータ制約

  • 型Tが符号なし整数型であること

事前条件

  • lが0より大きいこと

戻り値

Tのビット数をN(std::numeric_limits<T>::digits)とする。第nビット(0以上N未満)がxの第n % lビットに等しい値を返す。

例外

投げない

備考

  • 事前条件に違反する関数呼び出し式は、定数式として評価されない。

例

#include <bit>
#include <cstdint>
#include <print>

int main()
{
  // 最下位4ビットのパターン 0b1100 を繰り返す
  std::uint32_t r = std::bit_repeat(std::uint32_t{0xc}, 4);

  std::println("{:08x}", r);
}

出力

cccccccc

バージョン

言語

  • C++29

処理系

  • Clang: 22 ❌
  • GCC: 17 ✅
  • Visual C++: 2026 Update 2 ❌

関連項目

  • std::bit_reverse
  • std::bit_compress
  • std::bit_expand

参照

  • P3104R6 Bit permutations
    • C++29で追加された
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.