template< char FIRST, char... REST > struct binary
{
static_assert( FIRST == '0' || FIRST == '1', "invalid binary digit" ) ;
enum { value = ( ( FIRST - '0' ) << sizeof...(REST) ) + binary<REST...>::value } ;
};
template<> struct binary<'0'> { enum { value = 0 } ; };
template<> struct binary<'1'> { enum { value = 1 } ; };
template< char... LITERAL > inline
constexpr unsigned int operator "" _b() { return binary<LITERAL...>::value ; }
template< char... LITERAL > inline
constexpr unsigned int operator "" _B() { return binary<LITERAL...>::value ; }
typedef double signalf;
constexpr signalf operator"" _percent( long double val) { return val / 100 ; }
#include <iostream>
int main()
{
std::cout << 12.34_percent << '\n' // prints 0.1234
<< 10101_B << ", " << 011011000111_b << '\n' ; // prints 21, 1735
}
dGVtcGxhdGU8IGNoYXIgRklSU1QsIGNoYXIuLi4gUkVTVCA+IHN0cnVjdCBiaW5hcnkKewogICAgc3RhdGljX2Fzc2VydCggRklSU1QgPT0gJzAnIHx8IEZJUlNUID09ICcxJywgImludmFsaWQgYmluYXJ5IGRpZ2l0IiApIDsKICAgIGVudW0geyB2YWx1ZSA9ICggKCBGSVJTVCAtICcwJyApIDw8IHNpemVvZi4uLihSRVNUKSApICsgYmluYXJ5PFJFU1QuLi4+Ojp2YWx1ZSAgfSA7Cn07Cgp0ZW1wbGF0ZTw+IHN0cnVjdCBiaW5hcnk8JzAnPiB7IGVudW0geyB2YWx1ZSA9IDAgfSA7IH07CnRlbXBsYXRlPD4gc3RydWN0IGJpbmFyeTwnMSc+IHsgZW51bSB7IHZhbHVlID0gMSB9IDsgfTsKCnRlbXBsYXRlPCAgY2hhci4uLiBMSVRFUkFMID4gaW5saW5lCmNvbnN0ZXhwciB1bnNpZ25lZCBpbnQgb3BlcmF0b3IgIiIgX2IoKSB7IHJldHVybiBiaW5hcnk8TElURVJBTC4uLj46OnZhbHVlIDsgfQoKdGVtcGxhdGU8ICBjaGFyLi4uIExJVEVSQUwgPiBpbmxpbmUKY29uc3RleHByIHVuc2lnbmVkIGludCBvcGVyYXRvciAiIiB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