I have a long list of numbers between 0 and 67600. Now I want to store them using an array that is 67600 elements long. An element is set to 1 if a number was in the set and it
You should use std::bitset.
std::bitset
functions like an array of bool
(actually like std::array
, since it copies by value), but only uses 1 bit of storage for each element.
Another option is vector
, which I don't recommend because:
*For example, a standard-conforming function could expect &container.front()
to produce a pointer to the first element of any container type, which fails with std::vector
. Perhaps a nitpick for your usage case, but still worth knowing about.