27 #ifndef MPBLOCKS_UTIL_BINARY_LITERAL_H_
28 #define MPBLOCKS_UTIL_BINARY_LITERAL_H_
38 static_assert(std::numeric_limits<T>::is_integer,
"only integers allowed");
45 return std::numeric_limits<T>::digits;
57 constexpr
bool IsBinary(
char c) {
return c ==
'0' || c ==
'1'; }
60 template <
typename OutputType=
unsigned>
66 :
throw std::logic_error(
"char is not '0' or '1'");
69 template <
typename OutputType=
unsigned>
73 :
throw std::logic_error(
"Binary literal is too long for type");
79 #define BINARY_LITERAL(X) mpblocks::utility::BinaryLiteral(#X)
81 #if (__cplusplus >= 201103L)
82 constexpr
unsigned operator"" _b(
const char *
str ) {
87 #endif // MPBLOCKS_UTIL_BINARY_LITERAL_H_
constexpr unsigned _BinaryLiteral(const char *str, size_t val=0)
constexpr size_t NumberOfBits()
constexpr bool IsBinary(char c)
constexpr OutputType BinaryLiteral(const char *str, size_t val=0)
const Char8_t * str(const Char8_t *s1, const Char8_t *s2)
constexpr size_t StringLength(const char *str, size_t current_len=0)