numeric_bit_expand

numeric_bit_expand (std::bit_expand)

<bit> 헤더에 정의되어 있어요. x의 최하위 비트들을 선택해 mask에 1비트가 있는 위치에 펼쳐(place) 놓아요. 나머지 비트는 0이에요. C++29부터 도입됐어요.

출처: cppreference

본문

template< class T >
constexpr T bit_expand( T x, T mask ) noexcept;

(C++29부터)

x의 최하위 비트들을 선택해 mask에 1비트가 있는 위치에 펼쳐 놓아요. 나머지 비트는 0이에요.

매개변수

  • x: 펼칠 소스 값
  • mask: 펼치는 데 사용할 비트 마스크

타입 요구사항

  • T는 부호 없는 정수 타입이어야 오버로드 해석에 참여해요.

반환값

마스크 mask로 비트 전개(deposit)를 적용한 x.

주의 (Notes)

이 함수는 x86-64의 PDEP 명령과 ARM의 PDEP 명령과 같은 결과를 내요. 기능 테스트 매크로 __cpp_lib_bitops(202607L, C++29)는 비트 순열(bit permutation) 지원을 나타내요.

#include <bit>
#include <cstdint>

// x 의 연속된 최하위 비트들을 mask 위치로 펼침
auto r = std::bit_expand(std::uint8_t{0b0110}, std::uint8_t{0b1010'1010});

더 알아보기 (Learn more)

cppreference