Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- template<unsigned int NBITS>
- struct bitset {
- static constexpr unsigned int SIZE = NBITS;
- static constexpr unsigned int NWORDS = (NBITS & 63) ? ((NBITS>>6)+1) : (NBITS>>6);
- unsigned long words[NWORDS];
- unsigned int num_in_set;
- bitset() : num_in_set(0) {
- memset(words, 0, sizeof(words));
- }
- bool has(int ix) const {
- return (words[ix>>6] >> (ix & 63)) & 1;
- }
- void set(int ix) {
- unsigned long& w(words[ix>>6]);
- unsigned long b = 1UL << (ix & 63);
- if (!(w & b)) {
- w |= b;
- num_in_set++;
- }
- }
- void clr(int ix) {
- unsigned long& w(words[ix>>6]);
- unsigned long b = 1UL << (ix & 63);
- if (w & b) {
- w &= ~b;
- num_in_set--;
- }
- }
- };
- typedef bitset<32> bitset_combos;
- int main()
- {
- bitset_combos b;
- b.set(1);
- cout << b.num_in_set << endl;
- return 0;
- }
- $ clang++ -std=c++11 minimal.cpp
- minimal.cpp:39:9: error: unknown type name 'bitset'; did you mean '__bitset'?
- typedef bitset<32> bitset_combos;
- ^~~~~~
- __bitset
- /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/bitset:146:7: note: '__bitset' declared here
- class __bitset
- ^
- minimal.cpp:39:15: error: expected unqualified-id
- typedef bitset<32> bitset_combos;
- ^
- minimal.cpp:43:5: error: unknown type name 'bitset_combos'
- bitset_combos b;
- ^
- 3 errors generated.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement