fork(3) download
  1. #include <iostream>
  2. #include <limits>
  3. #include <bitset>
  4. #include <cstring>
  5. using namespace std;
  6.  
  7. template <class T>
  8. T umaxof()
  9. {
  10. T t;
  11. memset(&t, 0xFF, sizeof(T));
  12. return t;
  13. }
  14.  
  15. template <class T>
  16. size_t bitsof(const T& umax)
  17. {
  18. return bitset<sizeof(T)*8>(umax).count();
  19. }
  20.  
  21. int main()
  22. {
  23. struct A
  24. {
  25. uint32_t bf1:19;
  26. uint32_t bf2:1;
  27. };
  28.  
  29. cout << bitsof(umaxof<A>().bf1) << "\n";
  30. cout << bitsof(umaxof<A>().bf2) << "\n";
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
19
1