Files
biboumi/src/utils/binary.hpp
T
Florent Le Coz ccebe901d7 Check UTF-8 encoding, and convert strings to UTF-8
Handle conversion errors properly by inserting � instead.  Add a binary
header to provide portable way to write binary literals (I like them) Also
add a test file.  ref #2404
2013-11-09 06:01:47 +01:00

17 lines
506 B
C++

#ifndef BINARY_INCLUDED
# define BINARY_INCLUDED
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; }
#endif // BINARY_INCLUDED