fork(2) download
  1. template< char FIRST, char... REST > struct binary
  2. {
  3. static_assert( FIRST == '0' || FIRST == '1', "invalid binary digit" ) ;
  4. enum { value = ( ( FIRST - '0' ) << sizeof...(REST) ) + binary<REST...>::value } ;
  5. };
  6.  
  7. template<> struct binary<'0'> { enum { value = 0 } ; };
  8. template<> struct binary<'1'> { enum { value = 1 } ; };
  9.  
  10. template< char... LITERAL > inline
  11. constexpr unsigned int operator "" _b() { return binary<LITERAL...>::value ; }
  12.  
  13. template< char... LITERAL > inline
  14. constexpr unsigned int operator "" _B() { return binary<LITERAL...>::value ; }
  15.  
  16. typedef double signalf;
  17. constexpr signalf operator"" _percent( long double val) { return val / 100 ; }
  18.  
  19. #include <iostream>
  20.  
  21. int main()
  22. {
  23. std::cout << 12.34_percent << '\n' // prints 0.1234
  24. << 10101_B << ", " << 011011000111_b << '\n' ; // prints 21, 1735
  25. }
  26.  
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
0.1234
21, 1735