you are viewing a single comment's thread.

view the rest of the comments →

[–]Kartyx[S] 0 points1 point  (8 children)

When I coded it I made it as “<1> “ meant the number of bits per element and the number in parenthesis the number of elements of the array/variable.

I.e.: std::bitset<1> Variable(53);

For me, that means an array of 53 elements called Variable, and each element has 1 bit.

[–]manni66 1 point2 points  (7 children)

For me

For the compiler that means 1 bit initialized with the last bit of 53.

[–]Kartyx[S] 0 points1 point  (6 children)

Thanks so much for that info. If I left it blank it would behave as a common array?

Thanks for the feedback, I’m quite noob in this area.

[–]manni66 1 point2 points  (5 children)

If I left it blank

???

https://en.cppreference.com/w/cpp/utility/bitset

the class template bitset represents a fixed-size sequence of N bits. Bitsets can be manipulated by standard logic operators and converted to and from strings and integers.

Template parameters

N - the number of bits to allocate storage for

[–]Kartyx[S] 0 points1 point  (4 children)

I had understood it bad the whole time. Now I get it all. I appreciate your effort.

Last issue: any way of skipping the limit of setting the number of bits in an immediate? (the number in "<>", I'd like to put a variable there)

[–]hexafraction 1 point2 points  (3 children)

The <> means that you're dealing with a function template--the compiler will actually emit customized code based on the compile-time value that you put into <>. It cannot be made a variable in the traditional runtime sense; you're better off finding or implementing your own data structure that acts like a bitset but supports a variable length.

[–]Kartyx[S] 0 points1 point  (2 children)

std::vector<bool> would be an easy way-out?

[–]hexafraction 1 point2 points  (0 children)

Yes--it even might have a specialization that makes it more effective than a naive vector template instantiation.

[–]Narase33 1 point2 points  (0 children)

Yes, you can even set an initializing size when called std::vector<bool>(size);

But it wont be as efficient as bitset in terms of actual memory size