Advertisement
theosib

bitset compile error

Sep 29th, 2018
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1.  
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. template<unsigned int NBITS>
  7. struct bitset {
  8. static constexpr unsigned int SIZE = NBITS;
  9. static constexpr unsigned int NWORDS = (NBITS & 63) ? ((NBITS>>6)+1) : (NBITS>>6);
  10. unsigned long words[NWORDS];
  11. unsigned int num_in_set;
  12.  
  13. bitset() : num_in_set(0) {
  14. memset(words, 0, sizeof(words));
  15. }
  16.  
  17. bool has(int ix) const {
  18. return (words[ix>>6] >> (ix & 63)) & 1;
  19. }
  20. void set(int ix) {
  21. unsigned long& w(words[ix>>6]);
  22. unsigned long b = 1UL << (ix & 63);
  23. if (!(w & b)) {
  24. w |= b;
  25. num_in_set++;
  26. }
  27. }
  28. void clr(int ix) {
  29. unsigned long& w(words[ix>>6]);
  30. unsigned long b = 1UL << (ix & 63);
  31. if (w & b) {
  32. w &= ~b;
  33. num_in_set--;
  34. }
  35. }
  36. };
  37.  
  38.  
  39. typedef bitset<32> bitset_combos;
  40.  
  41. int main()
  42. {
  43. bitset_combos b;
  44. b.set(1);
  45. cout << b.num_in_set << endl;
  46.  
  47. return 0;
  48. }
  49.  
  50.  
  51.  
  52. $ clang++ -std=c++11 minimal.cpp
  53. minimal.cpp:39:9: error: unknown type name 'bitset'; did you mean '__bitset'?
  54. typedef bitset<32> bitset_combos;
  55. ^~~~~~
  56. __bitset
  57. /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/bitset:146:7: note: '__bitset' declared here
  58. class __bitset
  59. ^
  60. minimal.cpp:39:15: error: expected unqualified-id
  61. typedef bitset<32> bitset_combos;
  62. ^
  63. minimal.cpp:43:5: error: unknown type name 'bitset_combos'
  64. bitset_combos b;
  65. ^
  66. 3 errors generated.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement