C ++ initialization std :: bitset at compile time

I am trying to initialize std :: bitset <256 at compile time with some of its indices, let's say that 50-75 and 200-225 are set to 1.

Based on http://en.cppreference.com/w/cpp/utility/bitset/bitset Looks like my 2 options are:

constexpr bitset();
constexpr bitset( unsigned long long val ); 

Can someone shed some light on how I initialize my bitset, given that the second constructor will not work for large indexes?

+4
source share
2 answers

Bitset constexpr bitset( unsigned long long val ) , 64 ( unsigned long long - 64- ). 64 0, (. ):

std::bitset<70> bl(ULLONG_MAX); // [0,0,0,0,0,0,1,1,1,...,1,1,1] in C++11

, , string char*, (3) (4).

, 256 :

std::bitset<256> myBitset("111100000011111000001110000010101000100000100010010000100000000001111");
// I did not count the digits...
+1

, .

. b 0000000101111001:

std::bitset<16> b (std::string("0101111001"));
0

Source: https://habr.com/ru/post/1667300/


All Articles